Hello again AndersBank,
I've done something similar but with time. The approach I took, as it would apply to dates, is to search for the date, if it's not found take a day away and try the search again, if it's not found then add a day and try the search again, you keep doing this until you find the closest date either before or after the date your searching for.
Here is the code I used, you'll be able to adapt it.
Set rngStartRangeProcess = Application.Selection.Find(CStr(DateTime), LookIn:=xlValues) 'if date time not found then If rngStartRangeProcess Is Nothing Then Dim nRange As Integer For nRange = 1 To 15 'for a range of 15 seconds Dim newDateTime As Date newDateTime = DateAdd("s", nRange, DateTime) 'add seconds Set rngStartRangeProcess = Application.Selection.Find(CStr(newDateTime), LookIn:=xlValues) 'have another look If rngStartRangeProcess Is Nothing Then 'if still not found newDateTime = DateAdd("s", -nRange, DateTime) 'remove seconds Set rngStartRangeProcess = Application.Selection.Find(CStr(newDateTime), LookIn:=xlValues) 'have another look If Not rngStartRangeProcess Is Nothing Then 'if found then exit the for loop Exit For End If Else Exit For 'if found then exit loop End If Next End If
|