Setting LinkedCell of individual OptionButton

A

Angelito Cruz

I am creating multiple groupboxes with corresponding optionbuttons
inside it. I am having issues setting the LinkedCell property for
each radio button. For example, if I have 2 OptionButtons, I set the
LinkedCell of the first OptionButton to the right cell, when I add the second
OptionButton and set it's LinkedCell to the new .Address. The 1st OptionButton
is set to the new .Address.

Here's the code snippet when adding the OptionButton:


Public Sub InsertOptionButton(ByVal Target As Range, strGroupName As String)

Dim optBtn As OptionButton

Set WS = Application.ActiveWorkbook.Worksheets("Notes")

With Target

Set optBtn = WS.OptionButtons.Add _
(Top:=.Top + 4, Left:=.Offset(0, 0).Left + 40, Height:=.Height - 2.5, _
Width:=.Width / 2)

optBtn.Caption = ""
optBtn.Name = "opt" & .Address(0, 0)
optBtn.LinkedCell = .Address
optBtn.GroupBox.Name = strGroupName

End With

End sub


Thanks in advance,
Angelito
 
T

Tom Ogilvy

for optionbuttons from the forms toolbar, all optionbuttons in a group are
linked to the same cell. The cell then returns the sequence of the the
selected optionbutton.

So what you see is by design.
 
A

Angelito Cruz

Thanks Tom!

I figured out how to read the value of the option button on the cell
via this code:

Activesheet.optionbuttons("A3").value

Should I stay away from Optionbuttons from the forms toolbar and just
use the ActiveX equivalent? I am having the hardest time loading the
ActiveX OptionButton via VBA. I am sure it should be easier. Does
anyone have a code snippet I can look at? I will not be posting this
if I saw something that's close to what I am doing via the
Optionbutton from the forms toolbar.


Best Regards,
Angelito
 
T

Tom Ogilvy

If you want to add an option button from either toolbar using code, just
turn on the macro recorder and do it manually. This will give you the
specific code you need. You can then generalize it.

Which to use would depend on the functionality you want to achieve.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top