I still haven't opened Chip's workbook, but sometimes if you break up those long
formulas into its component pieces, things begin to make sense:
Option explicit
Sub aa()
Dim TempDate As Date
Dim myStr As String
Range("a1").Name = "statuscell"
TempDate = DateSerial(2003, 12, 31)
myStr = ""
myStr = Format(TempDate, "mmm d, yyyy")
myStr = " " & Format(dayofyear(TempDate), "##0")
myStr = numbersuffix(dayofyear(TempDate)) & " day of year."
'no errors on either of these
'But this caused an error
myStr = Format(Evaluate("NETWORKDAYS(" & """" & Format(Now(), _
"dd/mm/yy") & _
"""" & Application.International(xlListSeparator) & _
"""" & Format(TempDate, "dd/mm/yy") & """" & ")")) & ")"
'So I changed it.
myStr = Format(Evaluate("NETWORKDAYS(" & """" & CLng(Date) & _
"""" & Application.International(xlListSeparator) & _
"""" & CLng(TempDate) & """" & ")")) & ")"
'And it seemed to work ok.
End Sub
In fact, what I did was create a string and plop it into a cell. Then I put an
equal sign in front (manually) of it to see if excel yelled:
myStr = Format(Evaluate("NETWORKDAYS(" & """" & CLng(Date) & _
"""" & Application.International(xlListSeparator) & _
"""" & CLng(TempDate) & """" & ")")) & ")"
Range("b1").Value = myStr
The formula looked like:
=NETWORKDAYS("37972","37986")
I thought it was neat that =networkdays() coerced the text into real numbers,
but it seemed unnecessary to ask excel to do it.
next came:
myStr = "NETWORKDAYS(" & CLng(Date) & _
Application.International(xlListSeparator) & _
CLng(TempDate) & ")"
Range("b1").Value = myStr
And that put this string (formula after I added the =) in B1:
=NETWORKDAYS(37972,37986)
And that looked better to me.
So finally, I think that this will work ok:
Range("StatusCell").Value = Format(TempDate, "mmm d, yyyy") _
& " " & Format(dayofyear(TempDate), "##0") & _
numbersuffix(dayofyear(TempDate)) & " day of year." & _
" Days From Now: " & _
Format(DateDiff("d", Now(), TempDate), "##,##0") & _
" (Workdays: " & _
Format(Evaluate("NETWORKDAYS(" & CLng(Date) & _
Application.International(xlListSeparator) & _
CLng(TempDate) & ")")) & ")"
=======
But since you have the ATP (for both excel and VBA) loaded, you could put a
reference to the ATP (VBA side=atpvbaen.xls for me) and eschew (gesundheit) the
evaluate() stuff and just use it directly:
Range("StatusCell").Value = Format(TempDate, "mmm d, yyyy") _
& " " & Format(dayofyear(TempDate), "##0") & _
numbersuffix(dayofyear(TempDate)) & " day of year." & _
" Days From Now: " & Format(DateDiff("d", Now(), TempDate),
"##,##0") & _
" (Workdays: " & _
Format(NETWORKDAYS(CLng(Date), CLng(TempDate)))
These were my test functions. These return values! Good enough for my testing.
Function dayofyear(mydate As Date) As Long
dayofyear = mydate - DateSerial(Year(mydate) - 1, 12, 31)
End Function
Function numbersuffix(myNum As Long) As String
numbersuffix = Format(myNum, "000") & " "
End Function
========
The real question is: Could you pick the comments out of this mess of a post?
Norman Harker wrote:
<<snipped just to make it less ungodly! (ooh. another faith refence!>>