i have this udf and basically what I want to get is the latest date from a vector (column) that match with other data in other column, here's the code:
Option Explicit
Public Function GetLastDate(Carrier As String, CarrierVector As Range, DateVector As Range) As Variant
Dim TempRange(1 To 10) As Variant
Dim i, j As Integer
For i = 1 To DateVector.Rows.Count
With Application.WorksheetFunction
If .Text(CarrierVector.Item(i), "#") = Carrier And .IsError(.VLookup(DateVector.Item(i), TempRange, 1, False)) Then
j = j + 1
TempRange(j) = DateVector.Item(i)
End If
End With
Next i
GetLastDate = Application.WorksheetFunction.Max(TempRange)
End Function
in this case, if the Carrier variable is found on CarrierVector, the Date corresponding to that carrier will be storage on TempRange array, (this if it's not repeated) and at the end, it will return the lattest Date, but this doesn't work, it just return an error on the cell from where the function is called, could you please help me?