My VBA subroutine can't seem to find a row with a matching date.
My Objective: To find the row number of the first row in Sheet1 with a date equal to the oldest date in Sheet2
My process is:
- Find the row in Sheet2 with the oldest date
- Find the first row in Sheet1 with the same date and return the row number of that row.
What Happens
When I run my sub I get is Run-time error '91' - Object variable or With block variable not set. If I try "Msgbox FindRow Is Nothing" I get the true response.
This makes no sense, since in this system Sheet1 E6 has the same value as Sheet2 E8
MY DATA:
Sheet1 (E2 - E8):
09/10/2013
09/10/2013
14/11/2013
14/11/2013
17/11/2013
17/11/2013
20/11/2013
Sheet2 (E2 - E8):
01/12/2013
01/12/2013
27/11/2013
27/11/2013
24/11/2013
24/11/2013
20/11/2013
17/11/2013
My code so far:
Private Sub transferPostings()
Dim EarliesNewDate As Variant
Dim FirsCandidateOverlappingRow, rowCountHist, onlyNewRowsCount As Integer
Dim wsHist, wsNew As Worksheet
Dim possibleDuplicates, onlyNew, FindRow As Range
Set wsHist = Worksheets("Sheet1")
Set wsNew = Worksheets("Sheet2")
wsNew.Range("E1").End(xlDown).NumberFormat = "General"
Range(wsHist.Range("E2"), wsHist.Range("E2").End(xlDown)).NumberFormat = "General"
EarliesNewDate = wsNew.Range("E1").End(xlDown).Value
Set FindRow = Range(wsHist.Range("E2"), wsHist.Range("E2").End(xlDown)).Find(EarliesNewDate)
wsNew.Range("E1").End(xlDown).NumberFormat = "dd/mm/yyyy"
Range(wsHist.Range("E2"), wsHist.Range("E2").End(xlDown)).NumberFormat = "dd/mm/yyyy"
MsgBox FindRow.Row
End Sub
Any help with this problem is much appreciated.