Help w/date comparisons

cstimart

Well-known Member
Joined
Feb 25, 2010
Messages
1,180
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)

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
Any assistance would be appreciated.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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)

Rich (BB 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
Any assistance would be appreciated.

Found my error...I shall continue!
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,484
Members
452,917
Latest member
MrsMSalt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top