I have a problem I cannot for the life of me work out why there is a problem.
I have the following function.
Function WhatYear(pdate As Date)
'Application.Volatile
Dim year_count As Integer
Dim answer As Integer
Dim date_start As Date
Dim date_end As Date
year_count = 1982
answer = 0
While answer = 0
date_start = DateSerial(year_count, 4, 6)
date_end = DateSerial(year_count + 1, 4, 5)
If pdate >= date_start And pdate <= date_end Then
WhatYear = year_count
answer = 1
Else
year_count = year_count + 1
End If
Wend
year_count = 1982
answer = 0
End Function
It works out what tax year a date falls in. It has worked perfectly well. When it is downloaded from the net though it opens with the cell showing #NAME. If I use recalc or anything similar it doesn't change. The only way it comes up with an answer is if I edit and exit the cell. After that it works perfectly. Is there something wrong with this code? Or is it just something odd? TIA
Bookmarks