ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   renaming multiple buttons (https://www.excelbanter.com/excel-discussion-misc-queries/100676-renaming-multiple-buttons.html)

GreenBean

renaming multiple buttons
 
Hi all,

I have a worksheet with lots of OptionButtons which are named from
OptionButtion1 through to OptionButton266. Unfortunately I need to rename
to GW2opt1, etc - Is there anyway I can do this without having to change
each name individually? I've tried some VB but to no avail......

Tia



Norman Jones

renaming multiple buttons
 
Hi Green Bean,

If the option buttons are from the Forms toolbar, try:

'=============
Public Sub Tester()
Dim OP As OptionButton

For Each OP In ActiveSheet.OptionButtons
With OP
.Name = Replace(.Name, "OptionButton", "GW2opt")
End With
Next OP
End Sub
'<<=============


If, however, the option buttons are from the Controls Toolbox, try:

'=============
Public Sub Tester2()
Dim OleObj As OLEObject

For Each OleObj In ActiveSheet.OLEObjects
With OleObj
.Name = Replace(.Name, "OptionButton", "GW2opt")
End With
Next OleObj
End Sub
'<<=============


---
Regards,
Norman



"GreenBean" wrote in message
...
Hi all,

I have a worksheet with lots of OptionButtons which are named from
OptionButtion1 through to OptionButton266. Unfortunately I need to rename
to GW2opt1, etc - Is there anyway I can do this without having to change
each name individually? I've tried some VB but to no avail......

Tia




GreenBean

renaming multiple buttons
 
The second one worked perfectly - many thanks for help and saving me a
tedious task...


"Norman Jones" wrote in message
...
Hi Green Bean,

If the option buttons are from the Forms toolbar, try:

'=============
Public Sub Tester()
Dim OP As OptionButton

For Each OP In ActiveSheet.OptionButtons
With OP
.Name = Replace(.Name, "OptionButton", "GW2opt")
End With
Next OP
End Sub
'<<=============


If, however, the option buttons are from the Controls Toolbox, try:

'=============
Public Sub Tester2()
Dim OleObj As OLEObject

For Each OleObj In ActiveSheet.OLEObjects
With OleObj
.Name = Replace(.Name, "OptionButton", "GW2opt")
End With
Next OleObj
End Sub
'<<=============


---
Regards,
Norman



"GreenBean" wrote in message
...
Hi all,

I have a worksheet with lots of OptionButtons which are named from
OptionButtion1 through to OptionButton266. Unfortunately I need to
rename
to GW2opt1, etc - Is there anyway I can do this without having to change
each name individually? I've tried some VB but to no avail......

Tia







All times are GMT +1. The time now is 12:47 PM.

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