Hi all. Trying to figure out why this date disappears. Trying to get the instance with the oldest date. Sheet 2 has a column (16) with dates. Column 6 has my column that im checking for duplicates if its a duplicate, i want it to grab the oldest date.
not sure why this date is disappearing. any ideas?
[/CODE]
not sure why this date is disappearing. any ideas?
VBA Code:
[CODE=vba]Sub Find()
Dim dict As New Dictionary
Dim rg As Range
Set rg = Sheet2.Range("A3").CurrentRegion
Dim i As Long, RPUID As Long, InspectionDate As String
Dim MDI As Long, BLDG As Class_BLDG
For i = 4 To rg.Rows.Count
RPUID = rg.Cells(i, 6).Value
MDI = rg.Cells(i, 7).Value
InspectionDate = CDate(rg.Cells(i, 16).Value)
'Debug.Print InspectionDate
If dict.Exists(RPUID) = True Then ' if exists then
Set BLDG = dict(RPUID) 'get existing item at the key
Else
Set BLDG = New Class_BLDG 'initiates this instance for items not already in dictionary
dict.Add RPUID, BLDG ' adds RPUID (Key) to THIS BLDG.
End If
'Debug.Print InspectionDate
If BLDG.InspectionDate > InspectionDate Then
InspectionDate = BLDG.InspectionDate
End If
Debug.Print BLDG.InspectionDate
'BLDG.MDI = BLDG.MDI + MDI
'BLDG.InspectionDate = InspectionDate ' Adds inspection date to THIS RPUID(Key)
BLDG.MDI = MDI ' Adds MDI to THIS RPUID(Key)
Next i
End Sub