Excel UDF issue
So I'm trying to help a dude out at work and make a formula that will accomplish the following:
Compare a date to an array of dates on another sheet. If there is a match AND that date is today, I want it to return True. Else, it should return false.
I've tried the following two functions but neither one of them works...I get the same error with both. It claims the second parameter that is passed into the function is the wrong type and thus i get #VALUE! errors.
Function MatchDate(TPRrange As range, TPRDate As range) As Boolean
Application.Volatile (True)
Dim c
For Each c In ActiveWorkbook.range(TPRrange)
If c.Value = range(TPRDate) Then MatchDate = True
Exit For
Next
MatchDate = False
End Function
Function MatchDate2(TPRrange As range, TPRDate As Date) As Boolean
Application.Volatile (True)
Dim Index As Variant
' Find a match for the serial value of the date in the range A1:A10
' on Sheet1.
Index = Application.Match(CLng(TPRDate), range(TPRrange), 0)
' Display the results.
If IsError(Index) Then
MatchDate2 = True
Else
MatchDate2 = False
End If
End Function
Compare a date to an array of dates on another sheet. If there is a match AND that date is today, I want it to return True. Else, it should return false.
I've tried the following two functions but neither one of them works...I get the same error with both. It claims the second parameter that is passed into the function is the wrong type and thus i get #VALUE! errors.
Code:
Function MatchDate(TPRrange As range, TPRDate As range) As Boolean
Application.Volatile (True)
Dim c
For Each c In ActiveWorkbook.range(TPRrange)
If c.Value = range(TPRDate) Then MatchDate = True
Exit For
Next
MatchDate = False
End Function
Code:
Function MatchDate2(TPRrange As range, TPRDate As Date) As Boolean
Application.Volatile (True)
Dim Index As Variant
' Find a match for the serial value of the date in the range A1:A10
' on Sheet1.
Index = Application.Match(CLng(TPRDate), range(TPRrange), 0)
' Display the results.
If IsError(Index) Then
MatchDate2 = True
Else
MatchDate2 = False
End If
End Function