Calculate Business without the use of the Add-In (Analysis Tool-Pak)

R

Ron Rosenfeld

How do I calculate business days without using the analysis Tool-Pak.

How does this problem differ from the question you posted a few hours ago, and
to which you not only received responses, but you also responded that Bob's
solution worked?


--ron
 
N

Niek Otten

Wait for the next version of Excel, in which the ATP functions will be
integrated, I have understood.
Of course you can imitate the present BusinessDays functions of ATP, but it
sure is a lot of work.
What's your problem in using ATP?

--
Kind regards,

Niek Otten

"dannyboy213" <[email protected]>
wrote in message
news:[email protected]...
 
D

dannyboy213

Just to clarify, my last inquiry was to calculate the last business date
based on a given date. Now my current question is, how do I calculate
the business day from start date to end date w/o using the ATP. The
reason why I don't want to use the ATP is because not everyone who will
be viewing my file will have that add in.
 
R

Ron Rosenfeld

How do I calculate business days without using the analysis Tool-Pak.

Is it permissible to use a UDF (User Defined Function)? It would get
distributed with the workbook.

I had written one for just such an issue, and it basically mimics the Workday
Function.

If that would be helpful, I'd be happy to post it again.


--ron
 
N

Niek Otten

Hi Ron,

<I had written one for just such an issue, and it basically mimics the
Workday Function>

Just curious:

What made you that?
 
D

dannyboy213

Please do.

Ron Rosenfeld said:
Tool-Pak.

Is it permissible to use a UDF (User Defined Function)? It would get
distributed with the workbook.

I had written one for just such an issue, and it basically mimics the
Workday
Function.

If that would be helpful, I'd be happy to post it again.


--ron
 
R

Ron Rosenfeld

Hi Ron,

<I had written one for just such an issue, and it basically mimics the
Workday Function>

Just curious:

What made you that?

Same question was asked -- someone that wanted to use the Workday function, but
didn't want to install the ATP.

Best,
--ron
 
R

Ron Rosenfeld

Please do.


To enter, <alt><F11> opens the VB Editor.

Ensure your project is highlighted in the Project Explorer window, then
Insert/Module and paste the code below into the window that opens.

To use, enter =WD(start_date, num_days, [holidays]) into some cell.

The optional 'holidays' argument must be entered as a cell (range) reference,
however.

==================================
Function WD(StartDate As Date, ByVal NumDays As Long, _
Optional Holidays As Range = Nothing) As Date

'Workday function without Analysis Toolpak
'However, Holidays must be in a range

Dim i As Long
Dim TempDate As Date
Dim c As Range
Dim Stp As Integer

Stp = Sgn(NumDays)
TempDate = StartDate
For i = Stp To NumDays Step Stp
TempDate = TempDate + Stp
If Weekday(TempDate) = vbSaturday Then _
TempDate = TempDate + Stp - (Stp > 0)
If Weekday(TempDate) = vbSunday Then _
TempDate = TempDate + Stp + (Stp < 0)

If Not Holidays Is Nothing Then
Do Until Not IsError(Application.Match(CDbl(TempDate), Holidays, 0)) = False
If IsError(Application.Match(CDbl(TempDate), Holidays, 0)) = False Then
TempDate = TempDate + Stp
If Weekday(TempDate) = vbSaturday Then _
TempDate = TempDate + Stp - (Stp > 0)
If Weekday(TempDate) = vbSunday Then _
TempDate = TempDate + Stp + (Stp < 0)
End If
Loop
End If
Next i

WD = TempDate
End Function
===================================


--ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top