Option Buttons to change result

LarryJNX

New Member
Joined
Jul 3, 2008
Messages
18
This seems like it should be easy, but none of the methods I’ve tried have worked.
I have two option boxes (optYES and optNO as a response to the question “Is the building sprinklered?”). Then I have a combo box (cmbOccupancyGroup) and a label (lblTravelDistance). From the combo box, I would choose one of 26 options. Depending on the selection from the combo box and the YES/NO option (whether the building is sprinklered or not), the answer in lblTravelDistance will vary. I can get my code to choose and display one of the 26 options from the combo box, and I can get it to pass the correct value in lblTravelDistance when optYES is clicked. But I anticipate that someone may 1) forget to choose YES or NO, or 2) choose YES when they meant to choose NO and vice versa. So I want the value in lblTravelDistance to change depending on whether optYES or optNO is selected, and to go back and forth if the selection goes back and forth. Right now, that doesn’t work – the values don’t change. Here’s my code (I tried it both of the ways shown, but neither works)…
(A1 is an occupancy group, not a cell)...

Private Sub cmbOccupancyGroup_Change()
If optYES.Value = True And cmbOccupancyGroup.Value = "A1" Then
lblTravelDistance.caption = "250"
ElseIf optYES.Value = False And cmbOccupancyGroup.Value = "A1" Then
lblTravelDistance.caption = "200"
End If

If optYES.Value = True And cmbOccupancyGroup.Value = "A1" Then
lblTravelDistance.caption = "250"
ElseIf optNO.Value = True And cmbOccupancyGroup.Value = "A1" Then
lblTravelDistance.caption = "200"
End If
Do you see something here?
Larry
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
You need click event handlers for the option buttons and, since the label should be updated whenever any of the 3 controls are changed, put the code which updates the label in its own subroutine:
Code:
Private Sub cmbOccupancyGroup_Change()
    UpdateTravelDistance
End Sub

Private Sub optYes_Click()
    UpdateTravelDistance
End Sub

Private Sub optNo_Click()
    UpdateTravelDistance
End Sub

Private Sub UpdateTravelDistance()
    If optYes.Value = True And cmbOccupancyGroup.Value = "A1" Then
        lblTravelDistance.Caption = "250"
    ElseIf optYes.Value = False And cmbOccupancyGroup.Value = "A1" Then
        lblTravelDistance.Caption = "200"
    End If
    
    If optYes.Value = True And cmbOccupancyGroup.Value = "A1" Then
        lblTravelDistance.Caption = "250"
    ElseIf optNo.Value = True And cmbOccupancyGroup.Value = "A1" Then
        lblTravelDistance.Caption = "200"
    End If
End Sub
 
Upvote 0
Thanks, John_w. I guess I was half right; the solution was half-easy. So thanks very much for the input; I have it working the way it should now.
Larry
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top