Hey so I am having difficulty with this being very new at VBA. My objective is to use the data from the userform to populate cells determined by one of the userform entries. However, I want it to be a conditional entry. If there is a value in either one of 2 columns for 1 date, I want to have it move to the next column and check to see if they have any. Loop it to run in 4 separate pairs of columns sequentially (P+Q, V+W, AB+AC, AH+AI) and if there is a value in all of the 4 pairs, display a msgbox.
Here is my code which currently does NOT work:
Here is my code which currently does NOT work:
Code:
[COLOR=royalblue]Private Sub[/COLOR] cmdCreate_Click()
[COLOR=royalblue]If[/COLOR] Trim(Me.txtRef.Value) = "" [COLOR=royalblue]Then[/COLOR]
Me.txtRef.SetFocus
MsgBox "Please enter a reference #"
[COLOR=royalblue] Exit Sub[/COLOR]
[COLOR=royalblue]End If[/COLOR]
Application.EnableEvents = [COLOR=royalblue]False[/COLOR]
[COLOR=royalblue]Dim[/COLOR] LR&, i&
LR = Worksheets("Master").Range("F" & Rows.Count).End(xlUp).Row
[COLOR=royalblue]For[/COLOR] i = 4 [COLOR=royalblue]To[/COLOR] LR
[COLOR=royalblue]If[/COLOR] Worksheets("Master").Range("F" & i).Value = Me.txtRef.Value [COLOR=royalblue]And[/COLOR] _
Worksheets("Master").Range("P" & i).Value = "" [COLOR=royalblue]And[/COLOR] _
Worksheets("Master").Range("Q" & i).Value = "" [COLOR=royalblue]Then[/COLOR]
Worksheets("Master").Range("P" & i).Value = Me.txtFirst.Value
Worksheets("Master").Range("Q" & i).Value = Me.txtPaid.Value
[COLOR=royalblue]ElseIf[/COLOR] Worksheets("Master").Range("F" & i).Value = Me.txtRef.Value [COLOR=royalblue]And[/COLOR] _
Worksheets("Master").Range("V" & i).Value = "" [COLOR=royalblue]And[/COLOR] _
Worksheets("Master").Range("W" & i).Value = "" Then
Worksheets("Master").Range("V" & i).Value = Me.txtFirst.Value
Worksheets("Master").Range("W" & i).Value = Me.txtPaid.Value
[COLOR=royalblue]ElseIf[/COLOR] Worksheets("Master").Range("F" & i).Value = Me.txtRef.Value [COLOR=royalblue]And[/COLOR] _
Worksheets("Master").Range("AB" & i).Value = "" [COLOR=royalblue]And[/COLOR] _
Worksheets("Master").Range("AC" & i).Value = "" [COLOR=royalblue]Then[/COLOR]
Worksheets("Master").Range("AB" & i).Value = Me.txtFirst.Value
Worksheets("Master").Range("AC" & i).Value = Me.txtPaid.Value
[COLOR=royalblue]ElseIf[/COLOR] Worksheets("Master").Range("F" & i).Value = Me.txtRef.Value [COLOR=royalblue]And[/COLOR] _
Worksheets("Master").Range("AH" & i).Value = "" [COLOR=royalblue]And[/COLOR] _
Worksheets("Master").Range("AI" & i).Value = "" [COLOR=royalblue]Then[/COLOR]
Worksheets("Master").Range("AH" & i).Value = Me.txtFirst.Value
Worksheets("Master").Range("AI" & i).Value = Me.txtPaid.Value
[COLOR=royalblue]Else[/COLOR]: MsgBox "Employee has completed all scheduled payments. Please check for errors in previous dates."
Me.txtFirst.SetFocus
[COLOR=royalblue]Exit Sub[/COLOR]
[COLOR=royalblue] End If[/COLOR]
[COLOR=royalblue] Next[/COLOR] i
Application.EnableEvents = [COLOR=royalblue]True[/COLOR]
Me.txtRef.Value = ""
Me.txtFirst.Value = ""
Me.txtPaid.Value = ""
Me.txtRef.SetFocus
[COLOR=royalblue]End Sub[/COLOR]