In: Computer Science
Excel to VBA
Please post with screen shots
Add a few Check Box controls or Option Button controls to a worksheet and then use a Select/Case code structure in a sub procedure that outputs a message to the user telling him which box or option has been selected.
Below is the VBA code. Two sub procedure are created for two checkbox selection.
Code-
Private Sub CheckBox1_Click()
Dim num As Variant
If CheckBox1.Value = True Then num = 1 ' True condition of checkbox
1 selection
If CheckBox1.Value = False Then num = 2 ' False condition of
checkbox 1 selection
' Select to print values on conditions to be true
Select Case num
Case 1
MsgBox "The checkbox1 is SELECTED"
Case 2
MsgBox "The checkbox1 is UNSELECTED"
End Select
End Sub
Private Sub CheckBox2_Click()
' Logic for 2nd checkbox
Dim num2 As Variant
If CheckBox2.Value = True Then num2 = 3
If CheckBox2.Value = False Then num2 = 4
Select Case num2
Case 3
MsgBox "The checkbox2 is SELECTED"
Case 4
MsgBox "The checkbox2 is UNSELECTED"
End Select
End Sub
Code screenshot-
Output-