ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Visual Basic code (https://www.excelbanter.com/excel-programming/393619-visual-basic-code.html)

RitaJ

Visual Basic code
 
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


Jim Thomlinson

Visual Basic code
 
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
--
HTH...

Jim Thomlinson


"RitaJ" wrote:

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


Vergel Adriano

Visual Basic code
 
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



--
Hope that helps.

Vergel Adriano


"RitaJ" wrote:

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


Jim Thomlinson

Visual Basic code
 
Oops you wanted option buttons... Try this...

Sub RemoveButtons()
Dim btn As OptionButton

For Each btn In OptionButtons
btn.Delete
Next btn
End Sub
--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

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
--
HTH...

Jim Thomlinson


"RitaJ" wrote:

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


RitaJ

Visual Basic code
 
The code stopped in line "For Each btn in Buttons"
RJ


"Jim Thomlinson" wrote:

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
--
HTH...

Jim Thomlinson


"RitaJ" wrote:

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


RitaJ

Visual Basic code
 
Many Thanks.

Test 2 worked perfect.

RJ

"Vergel Adriano" wrote:

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



--
Hope that helps.

Vergel Adriano


"RitaJ" wrote:

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


Dave Peterson

Visual Basic code
 
If there aren't too many:

ActiveSheet.OptionButtons.delete

should work, too.

RitaJ wrote:

Many Thanks.

Test 2 worked perfect.

RJ

"Vergel Adriano" wrote:

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



--
Hope that helps.

Vergel Adriano


"RitaJ" wrote:

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


--

Dave Peterson

Jim Thomlinson

Visual Basic code
 
Thanks Dave. I didn't know you could do that.
--
HTH...

Jim Thomlinson


"Dave Peterson" wrote:

If there aren't too many:

ActiveSheet.OptionButtons.delete

should work, too.

RitaJ wrote:

Many Thanks.

Test 2 worked perfect.

RJ

"Vergel Adriano" wrote:

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



--
Hope that helps.

Vergel Adriano


"RitaJ" wrote:

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


--

Dave Peterson


Dave Peterson

Visual Basic code
 
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.

Jim Thomlinson wrote:

Thanks Dave. I didn't know you could do that.
--
HTH...

Jim Thomlinson

"Dave Peterson" wrote:

If there aren't too many:

ActiveSheet.OptionButtons.delete

should work, too.

RitaJ wrote:

Many Thanks.

Test 2 worked perfect.

RJ

"Vergel Adriano" wrote:

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



--
Hope that helps.

Vergel Adriano


"RitaJ" wrote:

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


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 07:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com