Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA EXCEL - Find the oldest date in a column

Tags:

excel

vba

Currently working on a function, and as part of it i need to find the oldest date in a column in VBA. Have spent a while looking for solutions but cant find much. I found one line however it doesn't actually work. Ill post the code snippet I have but any suggestions or solutions would be greatly appreciated!

Public Function SetSOWDates() As String

    Dim wsCRC As Worksheet
    Set wsCRC = Worksheets("CRC")

    Dim LastRowInCRC As Long

    LastRowInCRC = CRC.LastRowInCRC()

    LatestDate = Format(wsCRC.Max(Range("K8:K" & LastRowInCRC)), "dd/mm/yyyy")

    Debug.Print LatestDate

End Function
like image 590
SBozhko Avatar asked Oct 18 '25 15:10

SBozhko


1 Answers

You want Min, not Max for the oldest date, and it's a member of WorksheetFunction rather than the Worksheet:

LatestDate = Format(Worksheetfunction.Min(wsCRC.Range("K8:K" & LastRowInCRC)), "dd/mm/yyyy")
like image 65
Rory Avatar answered Oct 21 '25 14:10

Rory



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!