Reset option buttons, comboboxes and activex textboxes

Mikeymike_W

Board Regular
Joined
Feb 25, 2016
Messages
165
Hi,
I have the following bit of code which i use in a userform to reset it. I thought i would be able to use the same bit of code within a standard sheet using a command button linked to the code but it doesnt work, just throws an error at the me.control part. Would anyone know how to adapt for use within a sheet?
Many thanks in advance for your help.

VBA Code:
Private Sub CBILCReset_Click()

Dim oCtrl As Control
    For Each oCtrl In Me.Controls
        Select Case TypeName(oCtrl)
            Case "TextBox", "ComboBox"
                oCtrl.Value = ""
            Case "OptionButton"
                oCtrl.Value = False
        End Select
    Next oCtrl
    
End Sub
 

Some videos you may like

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,594
Office Version
  1. 2007
Platform
  1. Windows
This could be an option if they are ActiveX controls:

VBA Code:
Private Sub CBILCReset_Click()
  Dim oCtrl As OLEObject
 
  For Each oCtrl In ActiveSheet.OLEObjects
    If TypeOf oCtrl.Object Is MSForms.TextBox Or _
       TypeOf oCtrl.Object Is MSForms.ComboBox Then
        oCtrl.Object.Value = ""
    ElseIf TypeOf oCtrl.Object Is MSForms.OptionButton Then
        oCtrl.Object.Value = False
    End If
  Next oCtrl
End Sub
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,594
Office Version
  1. 2007
Platform
  1. Windows
I'm glad to help you. Thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,518
Messages
5,596,630
Members
414,082
Latest member
sasmita

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top