Re: Counting the Dates

Tech-Archive recommends: Fix windows errors by optimizing your registry



Function Index(Mnth As String, Dy As Long) As Long
Index = DatePart("y", DateValue(Mnth & " " & CStr(Dy) & ",2000"))
End Function

I don't use it often, but wouldn't DateSerial make more sense in the above function, and pass the Mnth by number instead of as a string?

I figured Webbiz would want to enter data in the same format that it is stored in the file (where the month is stored as a name). And, of course, as the function was set up, he only needs to enter a minimum of the first three letters of the month name for the function to work. However, we can expand the function to let the month be entered as a name (same minimum of first three letters) or as a number...

Function Index(Mnth As String, Dy As Long) As Long
If Mnth Like String(Len(Mnth), "#") Then
Index = DatePart("y", DateSerial(2000, Mnth, Dy))
Else
Index = DatePart("y", DateValue(Mnth & " " & CStr(Dy) & ",2000"))
End If
End Function

Rick

.



Relevant Pages