I am making a macro where I search through a spreadsheet of dates where each component of a date is already broken into separate components ie, year, month, day, hour, minute, second.
I want to compare these dates and find the earliest and latest date.
I was trying to concatenate the date components from strings into a Date variable, store the Dates in a Collection, and then search the Collection for the earliest and latest dates.
Dim dt As Date
Dim dtstring As String
Dim dates As New Collection
... [code where I just set unrelated variable values from cells and started a loop]
dtstring = "#" & day & "/" & month & "/" & year & " " & hour & ":" & minute & ":" & second & "#"
dt = dtstring
dates.Add dt 'add a Date into the dates collection
It doesn't like setting my Date variable value, dt, from a string but every example I find of this hard codes the Date variable with something similar to
Dim dteAppointment As Date = #8/2/2007 14:02:00#
whereas I need it set by the six date components.
Any help on this is much appreciated.