Thread: date function
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default date function

If you're passing ranges, then you don't need to use syntax like:

Function MatchDate1(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

Becomes:

Function MatchDate1(TPRrange As range, TPRDate As range) As Boolean

Dim c as range
For Each c In TPRrange
If c.Value = TPRDate.value Then MatchDate = True
Exit For
Next
MatchDate = False
End Function

And....

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

becomes

Function MatchDate2(TPRrange As range, TPRDate As Date) As Boolean

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), TPRrange, 0)

' Display the results.
If IsError(Index) Then
MatchDate2 = True
Else
MatchDate2 = False
End If
End Function



wrote:

You're right, it doesn't need to be volatile. In the first function I
tried it as a range but got #VALUE! errors. In the second function I
tried it as a date but still got #VALUE! errors with the second
argument.


--

Dave Peterson