Hi again all!
Hope all is well in your Macro lands!
I am trying to modify a code which I got feedback on but am still running through and trying to understand.
I have highlighted the modified section as bold - basically extending it to a range I want to copy but still loop based on the first cell in this data - is this possible?
The original thread is: http://www.excelforum.com/excel-prog...44#post3319444
Can someone highlight what I'm doing wrong?
Sub REFRESH_DATA()
'Defines PAYNUM as the variable for payroll numbers.
Dim PAYNUM As Variant, i As Long
'Turns off screen updating.
Application.ScreenUpdating = False
For j = 1 To 12
'****************************** STORE VARIABLES ******************************
'Sources sheet to store variables from.
With Sheets("Data - Month " & j)
'Stores each value in column A as a variable.
PAYNUM = .Range("A1", .Range("A:D" & Rows.Count).End(xlUp)).Value
End With
'****************************** COMPARE VARIABLES *****************************
'Sources sheet to compare to.
With Sheets("Summary")
If IsArray(PAUNUM) = True Then
'Loop through each PAYNUM variable.
For i = 1 To UBound(PAYNUM)
'Tests if the PAYNUM variable matches any value in column B.
If IsError(Application.Match(PAYNUM(i, 1), .Columns(2), 0)) Then
'If no match to PAYNUM variable is found adds value to the first empty cell in column B.
.Range("B" & Rows.Count).End(xlUp).Offset(1).Value = PAYNUM(i, 1)
End If
Next i
End If
End With
Next j
'****************************** CLOSE *****************************
'Turns on screen updating.
Application.ScreenUpdating = True
End Sub
Bookmarks