Reset option buttons, comboboxes and activex textboxes

Mikeymike_W

Board Regular
Joined
Feb 25, 2016
Messages
171
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
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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
Back
Top