Search code examples
excelvba

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.

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.

I am trying to fix it by snapping the buttons to a cell. This sub snaps to whichever cell the TopLeft of the button touches.

What I want is to snap the button to an exact range, such as Range("C5").

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

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