Visual Basic code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have somehow got thousnads of option buttons in my Excel worksheet. I would
like to write a simple code that would remove them using a macro instead of
manually deleting them. The option buttons are not in continuos numbers so
the code needs to check if the button exists first and then delete.

I am a novice and cannot write the above code.

Thanks
 
This code assumes you got your buttons from the Forms Toolbar...

Sub RemoveButtons()
Dim btn As Button

For Each btn In Buttons
btn.Delete
Next btn
End Sub
 
Hi,

If they are option buttons from the Control toolbox, then try something like
this:

Sub test()

Dim o As OLEObject

For Each o In ActiveSheet.OLEObjects
If TypeName(o.Object) = "OptionButton" Then
o.Delete
End If
Next o

End Sub


If they are option buttons from the Forms toolbox, then something like this:

Sub test2()

Dim b As OptionButton

For Each b In ActiveSheet.OptionButtons
b.Delete
Next b

End Sub
 
Oops you wanted option buttons... Try this...

Sub RemoveButtons()
Dim btn As OptionButton

For Each btn In OptionButtons
btn.Delete
Next btn
End Sub
 
Many Thanks.

Test 2 worked perfect.

RJ

Vergel Adriano said:
Hi,

If they are option buttons from the Control toolbox, then try something like
this:

Sub test()

Dim o As OLEObject

For Each o In ActiveSheet.OLEObjects
If TypeName(o.Object) = "OptionButton" Then
o.Delete
End If
Next o

End Sub


If they are option buttons from the Forms toolbox, then something like this:

Sub test2()

Dim b As OptionButton

For Each b In ActiveSheet.OptionButtons
b.Delete
Next b

End Sub
 
If there aren't too many:

ActiveSheet.OptionButtons.delete

should work, too.
 
The bad news is that it fails when that number of shapes gets large. But if you
know your worksheet (or can live with the error), then it's a nice way to start.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top