I have the following code:
I want the script to find the lowest date value in a row of dates, then, for each date value, write in the cell below it the difference (in days) between it and the minimum date.
The DateDiff line of code throws a "type mismatch" error when I do this. Both row 4 & 5 are formatted with identical date formats. Could someone please tell me why I get this error, while I've still got some hair left?
TIA
Code:
Sub datefunctions()
rightMostColumn = Range("A4").End(xlToRight).Column
Set myRange = Worksheets("temp").Range(Cells(4, 1), Cells(4, rightMostColumn))
mindate = Format(Application.WorksheetFunction.Min(myRange), "yyyymmdd")
For i = 1 To rightMostColumn
thisDate = Format(Cells(4, i), "yyyymmdd")
MsgBox (mindate & " " & thisDate)
Cells(5, i) = DateDiff("d", mindate, thisDate)
Next i
End Sub
The DateDiff line of code throws a "type mismatch" error when I do this. Both row 4 & 5 are formatted with identical date formats. Could someone please tell me why I get this error, while I've still got some hair left?
TIA