Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

With Excel VBA, how can I snap an Option Button on a sheet to a specific range?

I have a number of radio buttons (form option buttons, not activex) on a sheet. I am running into a problem where when I email the workbook, the option buttons distort and resize to an unusable size and in different positions. They look fine on my computer though so I don’t know what is causing this.

So, I am trying to fix it by snapping the buttons to a cell. I have used this sub to snap it to whichever cell the TopLeft of the button touches. But, what I want to do is snap the button to an exact range, such as Range("C5"). Is it possible to accomplish this?

Sub OptionButton_Align()

    With Sheets("Training").OptionButtons("Option Button 1")
        .Left = .TopLeftCell.Left
        .Top = .TopLeftCell.Top
        .Width = .TopLeftCell.Width
        .Height = .TopLeftCell.Height
    End With

End Sub

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Please try.

Sub OptionButton_Align()
    Dim rCell as Range
    Set rCell = Sheets("Training").Range("C5")
    With Sheets("Training").OptionButtons("Option Button 1")
        .Left = rCell.Left
        .Top = rCell.Top
        .Width = rCell.Width
        .Height = rCell.Height
    End With
End Sub
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading