1

I have a group of radio buttons with labels in adjacent cells. How can I arrange for the radio button with the label matching a target cell value to activate?

Here's an equivalent example to what I'm trying to achieve:

enter image description here

Here, you can see two radio groups: "buyer" and "destination". The labels are in column A, the radio groups are in column B, and the target values are in column C. The values in column C are what we control, and we want to activate the correct radio button by looking up the value of the target cell in the list of labels in column A. That is, if C2 changed to "Internal", then we want the radio button in cell B4 to activate. The radio buttons in B7 and B8 will be unaffected as they are in a different group.

2
  • So, just to be clear; when the user clicks on the LABEL, you want the RADIO button to activate.
    – zackrspv
    Feb 3, 2012 at 0:08
  • No, we want the radio button to activate when the value in the target cell changes to match the label. (not the OP, but sat next to him :-) )
    – regularfry
    Feb 3, 2012 at 0:14

1 Answer 1

2

You don't need to actually read the label value. You can assign the labels to option buttons and change the value of the option selected that way.

You could call this on the Worksheet_SelectionChange

Sub reflectCell()
 Dim targetedCell As String
 targetedCell = Range("A1").Text

Select Case UCase(targetedCell)
  Case "RED"
    ActiveSheet.OptionButton1.Value = True
  Case "BLUE"
    ActiveSheet.OptionButton2.Value = True
  Case "GREEN"
    ActiveSheet.OptionButton3.Value = True
End Select

End Sub

Unless you mean the label IS a cell value adjacent to the OptionButton Is the target cell a static Range location or the current ActiveCell?

If the target cell is always the same location you might control the input spelling like this. enter image description here

Here is another simpler approach

A non-macro solution that works if you can use formulas on the sheet is shown in this screen capture

option buttons example

Name each option button the same as the Label in column A Have it's linked cell be another cell (which can be hidden examples in E are the formulas showing in F) in that cell have it compare the input you provide to each cell label. Only one should end up being TRUE, (see example formulas)

Thus the option in B2 is linked to E2, B3 is linked to E3, B7 is linked to E7 etc. If you are allowed the extra column with formulas( and they can be anywhere) this is much simpler than using vba

5
  • Sorry, I should have been clearer. Yes, the labels are cell values. the target is a static Range location. We've been supplied with an "industry standard" spreadsheet designed for human input in this format, and there's a limit to how much we're allowed to change. We're just trying to automate "clicking" on the correct radio button.
    – user116587
    Feb 3, 2012 at 8:49
  • Any chance to see a small picture, even a couple cells? Might there be dozens of cells and only one item will be selected amongst them? You do mean when you say they are a group of radio buttons, only one may select in the group, right?
    – datatoo
    Feb 3, 2012 at 9:49
  • I've updated the question with a link to an example if that makes it clearer. In general there will only be a few radio buttons per group, but there are many groups.
    – user116587
    Feb 4, 2012 at 12:08
  • Is this a form that changes? How do the entries get made in column C? How many groups do you have in total?
    – datatoo
    Feb 4, 2012 at 16:04
  • Ah, so linked cells are bidirectional! Thanks, that's exactly what I was looking for.
    – user116587
    Feb 5, 2012 at 11:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .