Option Buttons

Mustakrakish

New Member
Joined
Nov 7, 2011
Messages
5
Hi everybody,

I need to make a macro which will insert 3 option buttons in list, gives them names and adds to each one of them another macros i made.

So far i manage to do this:

Sub Swtich()
ActiveSheet.OptionButtons.Add(95.25, 30, 48, 17.25).Select
ActiveSheet.Shapes("Option Button 1").Select
Selection.OnAction = "PERSONAL.XLSB!srm_vlookup"
ActiveSheet.OptionButtons.Add(95.25, 30, 48, 17.25).Select
ActiveSheet.Shapes("Option Button 1").Select
Selection.OnAction = "PERSONAL.XLSB!b11_vlookup"
ActiveSheet.OptionButtons.Add(95.25, 30, 48, 17.25).Select
ActiveSheet.Shapes("Option Button 1").Select
Selection.OnAction = "PERSONAL.XLSB!t3_vlookup"
End sub

I do not know how to put buttons in line so they are not on each other and also change their names.

Main idea is to put in many sheet this buttons for changing data in one collumn so the user can compare different things with actuals.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Welcome to MrExcel.

The arguments for the Add method are Left, Top, Width and Height so change those to suit. You can assign the OptionButton to an object variable like this:

Code:
    Dim Opt As OptionButton
    Set Opt = ActiveSheet.OptionButtons.Add(95.25, 30, 48, 17.25)
    With Opt
        .Name = "Opt1"
        .OnAction = "PERSONAL.XLSB!srm_vlookup"
    End With
 
Upvote 0

Forum statistics

Threads
1,226,693
Messages
6,192,464
Members
453,725
Latest member
cvsdatreas

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