Hi I have VBA code that I have written.......
It works but looks untidy.
Can someone offer advice on how to tidy it up with a loop so I can extend the ranges that are compared? (Extend to B3:30 & C3:C30)
thanks again
Mark
Office 365 Windows 10
It works but looks untidy.
Can someone offer advice on how to tidy it up with a loop so I can extend the ranges that are compared? (Extend to B3:30 & C3:C30)
Code:
Private Sub CommandButton1_Click()
'Security Pin
If Worksheets("Datasheet").Range("C3").Value = CStr(Me.PIN2.Text) And Worksheets("Datasheet").Range("B3").Value = CStr(Me.ComboBox1.Value) Then
GoTo ByPass
ElseIf Worksheets("Datasheet").Range("C4").Value = CStr(Me.PIN2.Text) And Worksheets("Datasheet").Range("B4").Value = CStr(Me.ComboBox1.Value) Then
GoTo ByPass
ElseIf Worksheets("Datasheet").Range("C5").Value = CStr(Me.PIN2.Text) And Worksheets("Datasheet").Range("B5").Value = CStr(Me.ComboBox1.Value) Then
GoTo ByPass
ElseIf Worksheets("Datasheet").Range("C6").Value = CStr(Me.PIN2.Text) And Worksheets("Datasheet").Range("B6").Value = CStr(Me.ComboBox1.Value) Then
GoTo ByPass
ElseIf Worksheets("Datasheet").Range("C7").Value = CStr(Me.PIN2.Text) And Worksheets("Datasheet").Range("B7").Value = CStr(Me.ComboBox1.Value) Then
GoTo ByPass
ElseIf Worksheets("Datasheet").Range("C8").Value = CStr(Me.PIN2.Text) And Worksheets("Datasheet").Range("B8").Value = CStr(Me.ComboBox1.Value) Then
GoTo ByPass
ElseIf Worksheets("Datasheet").Range("C9").Value = CStr(Me.PIN2.Text) And Worksheets("Datasheet").Range("B9").Value = CStr(Me.ComboBox1.Value) Then
GoTo ByPass
ElseIf Worksheets("Datasheet").Range("C10").Value = CStr(Me.PIN2.Text) And Worksheets("Datasheet").Range("B10").Value = CStr(Me.ComboBox1.Value) Then
GoTo ByPass
ElseIf Worksheets("Datasheet").Range("C11").Value = CStr(Me.PIN2.Text) And Worksheets("Datasheet").Range("B11").Value = CStr(Me.ComboBox1.Value) Then
GoTo ByPass
ElseIf Worksheets("Datasheet").Range("C12").Value = CStr(Me.PIN2.Text) And Worksheets("Datasheet").Range("B12").Value = CStr(Me.ComboBox1.Value) Then
GoTo ByPass
ElseIf Worksheets("Datasheet").Range("C13").Value = CStr(Me.PIN2.Text) And Worksheets("Datasheet").Range("B13").Value = CStr(Me.ComboBox1.Value) Then
GoTo ByPass
ElseIf Worksheets("Datasheet").Range("C14").Value = CStr(Me.PIN2.Text) And Worksheets("Datasheet").Range("B14").Value = CStr(Me.ComboBox1.Value) Then
GoTo ByPass
ElseIf Worksheets("Datasheet").Range("C15").Value = CStr(Me.PIN2.Text) And Worksheets("Datasheet").Range("B15").Value = CStr(Me.ComboBox1.Value) Then
GoTo ByPass
Else
MsgBox Prompt:="Incorrect PIN", Buttons:=vbCritical
Me.PIN2.Value = ""
Unload Me
GoTo ReTry
ByPass:
End If
Call Signnow
ReTry:
End Sub
thanks again
Mark
Office 365 Windows 10
Last edited: