How to Clear ComboBox and Optionbutton and text...

Realjoshtodd

New Member
Joined
Sep 26, 2017
Messages
34
Ok I have the following code listed below to clear the Optionbuttons and any text from parts of Sheet 2. I need to also reset and clear the ComboBox (there is 8) to be blank. There is also two text boxs that I need to clear as well. When I add

ElseIf TypeName(box.Object) = "Combobox" Then
box.Object.Clear

it gives me an error.




Sub ClearAll()
Dim box As OLEObject
Worksheets("Sheet2").Rows("1:1").ClearContents
Worksheets("Sheet2").Range("M4").ClearContents
Worksheets("Sheet2").Range("F12", "J12").ClearContents

For Each box In ActiveSheet.OLEObjects
If TypeName(box.Object) = "OptionButton" Then
box.Object.Value = False
ElseIf TypeName(box.Object) = "CheckBox" Then
box.Object.Value = False
ElseIf TypeName(box.Object) = "ListBox" Then
box.Object.Clear
End If
Next box
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Which line gives you an error? Also, what type of error are you getting?

Note that if you used the ListFillRange property to specify the range, you'll need to use the same property to clear it...

Code:
box.ListFillRange = ""
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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