Hello,
I have a userform created that has 3 frames that contain 3 optionbuttons. Each frame contains the same optionbuttons.
Frame 1 has 3 buttons: Thursday, Friday And Saturday
Frame 2 and 3 have the same options.
What I need to do is if Frame1 option matches the selection in Frame 2 or 3, display an error message. Same goes for Frame2 matching Frame1 and 3 etc.
Below is the code I have.
When I test this out and dont click duplicate days, I am still getting the msgbox popping up saying i have selected the same day twice. Can anyone tell me what I have wrong in this code?
Here is my full code if this helps:
I have a userform created that has 3 frames that contain 3 optionbuttons. Each frame contains the same optionbuttons.
Frame 1 has 3 buttons: Thursday, Friday And Saturday
Frame 2 and 3 have the same options.
What I need to do is if Frame1 option matches the selection in Frame 2 or 3, display an error message. Same goes for Frame2 matching Frame1 and 3 etc.
Below is the code I have.
Code:
If OptionButton1.Value = True And OptionButton6.Value Or OptionButton9.Value = True Then
MsgBox "You have selected the same day twice. Please choose again.", vbExclamation, "Same Day Selected"
Exit Sub
ElseIf OptionButton2.Value = True And OptionButton5.Value Or OptionButton8.Value = True Then
MsgBox "You have selected the same day twice. Please choose again.", vbExclamation, "Same Day Selected"
Exit Sub
ElseIf OptionButton3.Value = True And OptionButton4.Value Or OptionButton7.Value = True Then
MsgBox "You have selected the same day twice. Please choose again.", vbExclamation, "Same Day Selected"
Exit Sub
End If
When I test this out and dont click duplicate days, I am still getting the msgbox popping up saying i have selected the same day twice. Can anyone tell me what I have wrong in this code?
Here is my full code if this helps:
Code:
Private Sub Submit_Click()
Dim First As Variant
Dim Second As Variant
Dim Third As Variant
If BadgeNumber.Text = "" Then
MsgBox "Please Scan Your Badge", vbExclamation, "Badge Number Missing"
Exit Sub
ElseIf OptionButton1.Value = False And OptionButton2.Value = False And OptionButton3.Value = False Then
MsgBox "You have not selected your First Option.", vbExclamation, "Option 1 Not Selected"
Exit Sub
ElseIf OptionButton4.Value = False And OptionButton5.Value = False And OptionButton6.Value = False Then
MsgBox "You have not selected your Second Option.", vbExclamation, "Option 2 Not Selected"
Exit Sub
ElseIf OptionButton7.Value = False And OptionButton8.Value = False And OptionButton9.Value = False Then
MsgBox "You have not selected your Third Option.", vbExclamation, "Option 3 Not Selected"
Exit Sub
End If
If OptionButton1.Value = True And OptionButton6.Value Or OptionButton9.Value = True Then
MsgBox "You have selected the same day twice. Please choose again.", vbExclamation, "Same Day Selected"
Exit Sub
ElseIf OptionButton2.Value = True And OptionButton5.Value Or OptionButton8.Value = True Then
MsgBox "You have selected the same day twice. Please choose again.", vbExclamation, "Same Day Selected"
Exit Sub
ElseIf OptionButton3.Value = True And OptionButton4.Value Or OptionButton7.Value = True Then
MsgBox "You have selected the same day twice. Please choose again.", vbExclamation, "Same Day Selected"
Exit Sub
End If
RowCount = Worksheets("Sheet6").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Sheet6").Range("A1")
.Offset(RowCount, 0).Value = Me.BadgeNumber.Value
If OptionButton1.Value = True Then
.Offset(RowCount, 5).Value = "Thursday"
ElseIf OptionButton2.Value = True Then
.Offset(RowCount, 5).Value = "Friday"
ElseIf OptionButton3.Value = True Then
.Offset(RowCount, 5).Value = "Saturday"
End If
If OptionButton4.Value = True Then
.Offset(RowCount, 6).Value = "Saturday"
ElseIf OptionButton5.Value = True Then
.Offset(RowCount, 6).Value = "Friday"
ElseIf OptionButton6.Value = True Then
.Offset(RowCount, 6).Value = "Thursday"
End If
If OptionButton7.Value = True Then
.Offset(RowCount, 7).Value = "Saturday"
ElseIf OptionButton8.Value = True Then
.Offset(RowCount, 7).Value = "Friday"
ElseIf OptionButton9.Value = True Then
.Offset(RowCount, 7).Value = "Thursday"
End If
End With
MsgBox "Congratulations. Your votes have been recorded."
End Sub