Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I need a visual basic code....please Rhonda Excel Discussion (Misc queries) 1 March 5th 07 01:18 PM
Visual Basic Code amirstal Excel Programming 1 December 8th 06 04:40 PM
VISUAL BASIC CODE Josephine Ng Excel Programming 2 May 18th 06 06:45 AM
visual basic code Whitey Excel Programming 1 October 26th 04 04:05 PM
Visual Basic Code Robert Couchman Excel Programming 2 February 2nd 04 03:10 PM


All times are GMT +1. The time now is 03:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"