PDA

View Full Version : [SOLVED:] CANNOT PLACE BUTTON IN SPECIFIED LOCATION



DeanP
12-16-2018, 11:25 AM
I am running a macro that places an option button in my worksheet. However, I cannot place it in the location I want. When running the macro the button is placed wherever the cursor is.

I tried the running the macro using:


Sub ShowPerBox()
Dim rng As Range
Set rng = ActiveSheet.Range("L18")
With ActiveSheet.OptionButtons.Add(Selection.Left, Selection.Top, Selection.Width, Selection.Height)
.Name = "OptionButton1"
.Caption = "CONFIRM"
End With

End Sub

Am I missing something?

Fluff
12-16-2018, 12:26 PM
Try
Sub ShowPerBox()
Dim rng As Range
Set rng = ActiveSheet.Range("L18")
With ActiveSheet.OptionButtons.Add(rng.Left, rng.Top, rng.Width, rng.Height)
.Name = "OptionButton1"
.Caption = "CONFIRM"
End With

End Sub

Stohan
12-16-2018, 12:31 PM
Hi there


With ActiveSheet.OptionButtons.Add(Selection.Left, Selection.Top, Selection.Width, Selection.Height)
Selection here means that button will place in the area which is selected, if you select amount of cells it will cover them. Or if not, it will be placed in the area of the cursor.

To make it way you want replace it with for example (30,30,30,30) , it will place button in the area of 3 cells with width and height of 2 cells. (default cells 15x15)

Best of luck!

DeanP
12-16-2018, 01:25 PM
Thank you both!!

How can I change the font of the button to:

Source Sans Pro - Size 14 - Bold

Fluff
12-16-2018, 01:42 PM
Not sure that you can

Stohan
12-16-2018, 03:21 PM
For just button there is not that property, but you can use ActiveX command button and useCommandButton1.BackColor = 12713921.