The List of Employee Names dataset displays the ID and Employee Names. We can use the Scroll Bar to move across the list of employees. You can remove Form Controls in many ways using Excel’s built-in options and VBA code.
Method 1 – Using Find and Select Option
Steps:
- Click the Find & Select option in the Editing group >> Click the Go To Special option.
This opens the Go To Special wizard.
- Choose Objects >> Press the OK button.
- Select all the objects in the worksheet >> press DELETE.
This eliminates the Scroll Bar, as shown in the image below.
Read More: Key Differences in Excel: Form Control Vs. ActiveX Control
Method 2 – Using a Keyboard Shortcut
Steps:
- Press the F5 key, which opens the Go To dialog box.
- Click the Special option at the bottom.
- Choose Objects >> Click OK.
- Press DELETE to remove the Form Control object.
Your output should look like the picture given below.
Read More: How to Use Form Controls in Excel
Method 3 – Applying VBA Code
3.1 Removing Form Controls Buttons
- Go to the Developer tab >> Click the Visual Basic button.
This opens the Visual Basic Editor in a new window.
- Go to the Insert tab >> select Module.
Copy the code from here and paste it into the window below:
Sub Remove_Form_Control_Buttons()
Dim FrmCtrl_button As Object
On Error Resume Next
ActiveSheet.Buttons.Delete
For Each FrmCtrl_button In ActiveSheet.OLEObjects
If TypeName(FrmCtrl_button.Object) = "CommandButton" Then
FrmCtrl_button.Delete
End If
Next
End Sub
⚡ Code Breakdown:
Now, I will explain the VBA code removing Form Controls, which is divided into 2 steps.
- In the first portion, the sub-routine is given a name, here it is Remove_Form_Control_Buttons().
- Next, define the variables FrmCtrl_button as Objects.
- In the second potion, use the For Loop and the If statement to remove the objects from the worksheet using the Delete method.
- Close the VBA window >> click the Macros button.
This opens the Macros dialog box.
- Select the Remove_Form_Control_Buttons macro >> Press Run.
The results should look like the screenshot given below.
3.2 Removing Form Controls Checkboxes
Steps:
- Run Steps 1-2 from the previous methods to open the Visual Basic editor, insert a new module and enter the code:
Sub Remove_Form_Control_Checkboxes()
For Each FrmCtrl_ChBox In ActiveSheet.Shapes
If FrmCtrl_ChBox.Type = msoFormControl Then
If FrmCtrl_ChBox.FormControlType = 1 Then FrmCtrl_ChBox.Delete
End If
Next
End Sub
⚡ Code Breakdown:
Now, I will explain the VBA code removing Form Controls.
- First, the sub-routine is given a name, here it is Remove_Form_Control_Checkboxes().
- Next, use the For Loop and the If statement to loop through all the cells and remove the checkboxes.
- Close the VBA window >> click the Macros button >> run the Remove_Form_Control_Checkboxes macro.
The results should appear in the image given below.
3.3. Removing All Form Controls
Steps:
- Open the Visual Basic editor >> insert a new module and copy and paste the code:
Sub Remove_All_Objects()
On Error Resume Next
ActiveSheet.DrawingObjects.Visible = True
ActiveSheet.DrawingObjects.Delete
On Error GoTo 0
End Sub
⚡ Code Breakdown:
Here, I will explain the code for eliminating all Form Controls objects.
- In the first portion, the sub-routine is given a name; here, it is Remove_All_Objects().
- Next, use the ActiveSheet.DrawingObjects property to make all the objects visible, and then use the Delete method to remove them.
- Exit the VBA window >> press the Macros button >> execute the Remove_All_Objects macro.
Your output should look like the picture given below.
How to Delete a Macro Button in Excel
Considering the Project List dataset, which contains the Names of the staff and their designated Project Names, respectively, we can click the Run Macro button to highlight each project in a different color.
Steps:
- Execute Steps 1-2 from the previous methods to open the Visual Basic editor, insert a new module, and enter the VBA code:
Sub Remove_All_Objects()
On Error Resume Next
ActiveSheet.DrawingObjects.Visible = True
ActiveSheet.DrawingObjects.Delete
On Error GoTo 0
End Sub
- Close the VBA window >> click the Macros button >> run the Remove_All_Objects macro.
This eliminates the macro button, as shown in the screenshot below.
Practice Section
We have provided a Practice section on the right side of each sheet so you can practice.
Download the Practice Workbook
You can download the practice workbook from the link below.
Related Articles
<< Go Back to Form Control in Excel | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!