I have both next and for and I am still getting this error message saying "next without for". Can someone please help me with this error message? What am i doing wrong here?
Sub CheckCOA()
new_coa_detected = 0
Sheets("CAO & other").Select
With ActiveSheet
lr = .Cells(.Rows.Count, "A").End(xlUp).Row
MsgBox "Ref Table Length = " & lr
End With
Sheets("Month1").Select
With ActiveSheet
lr1 = .Cells(.Rows.Count, "A").End(xlUp).Row
MsgBox "Month 1 Length = " & lr1
End With
For l = 2 To lr1
code = Cells(l, 1)
Sheets("CAO & other").Select
For m = 2 To lr
If Cells(m, 1) = code Then
GoTo existing_code
End If
Next m
new_code:
'New code detected
Sheets("NewCOAsDetected").Select
With ActiveSheet
lr_new_coa = .Cells(.Rows.Count, "A").End(xlUp).Row
Cells(lr_new_coa, 1) = code
new_coa_detected = 1
Sheets("Month1").Select
existing_code:
'No action for existing code. Check next code
Next l
If new_coa_detected = 1 Then
MsgBox "New COA codes have been detected. A list of these COA codes is available under the 'NewCOAsDetected' tab."
End If
End Sub