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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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