Networkdays function

  • Thread starter Thread starter Jenn
  • Start date Start date
J

Jenn

Here is the formula I am using right now:

=NETWORKDAYS(H8,F8)

But, if F8 is blank, how can I get this formula to also
leave the answer blank? In other words, I only want the
answer if both H8 and F8 are populated with dates.

Thank you!
 
Hi Jenn!

Try:

=IF(F8="","",NETWORKDAYS(H8,F8))

But note here that you will get the dreaded #VALUE! if F8 is not blank
but contains text.

The trouble is that Excel does not have an ISDATE function. However
you can easily roll your own because VBA does have one. Just put the
following in a Module:

Function ISADATE(MyCell As Range)
ISADATE = IsDate(MyCell)
End Function

Now you can use:

=IF(ISADATE(F8),NETWORKDAYS(H8,F8),"")


--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
(e-mail address removed)
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
 
:-) Hey there stranger - Hasn't been the same without you. And the next time
you mention how we are doing in the cricket, I'm just going to shout 'Goooooooo
Johnny Wilkinson' ;-)
 
Hi Ken!

Back after a very heavy semester. But feeling a bit rusty! Must put
some Single Malt into the system.

As long as you don't mention India we'll get on just fine! But with
our first string bowlers all out, we couldn't expect much different.

--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
(e-mail address removed)
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
 
...
...
The trouble is that Excel does not have an ISDATE function. However
you can easily roll your own because VBA does have one. Just put the
following in a Module:

Function ISADATE(MyCell As Range)
ISADATE = IsDate(MyCell)
End Function
...

UDFs are rather slow compared to built-in worksheet functions. A few built-in
worksheet functions could be used to do this.

(ISNUMBER(DATEVALUE(X))+ISNUMBER(FIND(CELL("Format",X),"D1 D2 D3 D4 D5"))>0)

This reproduces the results from VBA's IsDate function when X is a range. Note
that neither approach works for standard date arithmetic. The UDF chokes on
anything other than ranges, and if its argument type is changed to variant, it
returns False for ISADATE(TODAY()), which is nonobvious. The built-in formula
approach won't even accept nonrange X in the CELL function.
 
Back
Top