Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a radio button with YES/NO option. What I require is that another cell gets activated/highlighted ONLY when radio button YES is clicked, and not when radio button No is clicked. For example:

Column 1.......| Column 2...............| Column 3.......| Column 4.|

Have Laptop?| (radio_buton) YES.| Which Brand: |.................|

......................| (radio_buton) NO...|.......................|.................|

I have less reputation points , so couldn't paste image. But 've tried to imitate Excel sheet.(sorry, bear with me)

Refering to this image, I want that when i click on YES radio button , "Which Brand" field gets activated/highlighted asking for user input. However, if I click NO, then nothing happens.

I've tried searching for its solution at various sites, but in vain. Any help will be really appreciated.

Thanks.

share|improve this question

2 Answers 2

Use the Excel macro recorder. Its perfect for such tasks.

  1. Right click your YES-button
  2. Select Assign macro → a new dialog opens
  3. Click record & ok → the dialog disappears and you can start recording
  4. Do your actions → Select your Which brand cell
  5. Go to View → Macros → Stop recording

Now, every time you click the YES-button, the underlying VBA code is executed and performs all your recorded actions again. If you want to add more actions, press ALT+F8 to open the VBA editor.

(tested with Office 2013)

share|improve this answer

Start in Design Mode in the Developer tab of the ribbon and right-click on the Yes button and choose View Code. (I've renamed the button "obYes".)

Choose 'View Code' after right-clicking Yes button.

That will bring up the VBA code editor with an empty procedure for the code that will be run each time the Yes option button is chosen.

The code edit with empty procedure for action to take when Yes button is chosen

Here's where some choices need to be made on exactly what should happen when the Yes button is chosen.

For this example, I've assumed that three things should occur:

  • The cell where the user will enter the brand of the laptop should be selected.
  • The fill color of that cell should change.
  • A message should appear to reinforce what the user is expected to do.

The best way to figure out what code is needed is to use the macro recorder to generate the basic code, which can then be customized (and usually shortened) to do exactly what you want).

It may be necessary to supplement the macro recorder with a Google search. The first two of the things are easy to find using the search terms "excel vba select cell" and "excel vba set cell color".

The third one - the message to the user - is a little tougher, but only because it's necessary to decide exactly how the message should be delivered: A popup box? Text inserted into a neighboring cell? Something else?

In this case, I've chosen Excel's data validation feature, which conveniently can be set to pop up a message when a cell is selected.

Here's the code for both the Yes and the No buttons. (The cryptic 7-digit number for the cell interior color in the Yes code is what the macro recorder recorded when I selected green for the fill color.)

Option button code.

The result pretty much works as intended. When the Yes button is chosen, the data entry cell is selected, its color turns green, and a message pops up. When the No option button is selected, the cell is cleared.

Data entry cells with yes and no option buttons selected.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.