Hi,
I am a novice to vba.
I am trying to create a custom function to compare a given date with today's date and
if the difference between the given date and today's date is more than 14 days then
display the difference in dates in the worksheet cell and highlight it.
else,
display the difference in dates in the worksheet cell
my code looks as follows:
My code is working properly, if TestDates(dt) <= 14, else it is displaying #VALUE! in the worksheet.
Please help!!
I am a novice to vba.
I am trying to create a custom function to compare a given date with today's date and
if the difference between the given date and today's date is more than 14 days then
display the difference in dates in the worksheet cell and highlight it.
else,
display the difference in dates in the worksheet cell
my code looks as follows:
Code:
Function TestDates(pDate1 As Date) As Long
TestDates = DateDiff("d", pDate1, Date)
End Function
Function cond_format(dt As Date) As Variant
If TestDates(dt) > 14 Then
cond_format = TestDates(dt)
Debug.Print cond_format
ActiveCell.Cells.Interior.Color = RGB(0, 0, 255)
ElseIf TestDates(dt) <= 14 Then
cond_format = TestDates(dt)
Debug.Print cond_format
End If
End Function
My code is working properly, if TestDates(dt) <= 14, else it is displaying #VALUE! in the worksheet.
Please help!!
Last edited by a moderator: