I'm trying to create a macro that will do the following...
Sheet1 contains 5 columns of data, pertinent ones being...
Col B = ID
Col C = Location
Col D = Start Date
Col E = End Date (blank if still active)
Sheet2 contains 13 columns of data, pertinent ones being...
Col A = Pay Period Start Date
Col B = Pay Period End Date
Col E = ID
In Sheet2.Column N, I want to fill the Sheet1.Column D that corresponds to the appropriate ID and Pay Period.
I started by creating a Function, but the first comparison of dates does work properly. for example in Cell C2, I would use =Place(N2)
Any assistance would be appreciated.
Sheet1 contains 5 columns of data, pertinent ones being...
Col B = ID
Col C = Location
Col D = Start Date
Col E = End Date (blank if still active)
Sheet2 contains 13 columns of data, pertinent ones being...
Col A = Pay Period Start Date
Col B = Pay Period End Date
Col E = ID
In Sheet2.Column N, I want to fill the Sheet1.Column D that corresponds to the appropriate ID and Pay Period.
I started by creating a Function, but the first comparison of dates does work properly. for example in Cell C2, I would use =Place(N2)
Code:
Function Place(rng As Range)
Dim i As Integer
Dim LR As Integer
Dim EmpID As Integer
EmpID = rng.Offset(0, -9).Value
Place = ""
LR = Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LR
If EmpID = Sheets(1).Range("B" & i) Then
If Sheets(1).Range("D" & i).Value >= rng.Offset(0, 13).Value Then
Place = Sheets(1).Range("C" & i)
End If
End If
Next i
End Function