Workday Function in VBA

charbona

Board Regular
Joined
Nov 6, 2008
Messages
124
Something is not working right and I am not sure what it is...

I am trying to use the Workday function as a part of a macro - if myLTD is greater than myBMLT then I want to set myIRD by using the workday function - taking mySD (start date) plus a set # of days (my LTD + 2 days), and include the holidays located at "Worksheets("Parameters").Range("A2:A30"))". See code below...


Code:
Set mySD = ActiveCell
Set myLTD = ActiveCell.Offset(0, 9)
If myLTD > myBMLT Then
    Set myIRD = WorksheetFunction.WorkDay(mySD, myLTD + 2, Worksheets("Parameters").Range("A2:A30"))
 
End If
 
MsgBox myIRD
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Don't use "Set". You only use Set when dealing with objects (ranges, OLEObjects, worksheets, etc.), not numeric/string variables.
 
Upvote 0
The Workday Function is part of the Analysis Toolpack Addin.

To use ATP functions in VBA, you need to set a refernce to the Analysis Toolpack..
In VBA window, click tools - references
Check atpvbaen.xls

Then, you don't use the Application or Worksheet function object..
And as pointed out above, you don't use Set with this function..

Instead of
Set myIRD = WorksheetFunction.WorkDay(....

You write
myIRD = WorkDay(....
 
Upvote 0
The Workday Function is part of the Analysis Toolpack Addin.

To use ATP functions in VBA, you need to set a refernce to the Analysis Toolpack..
In VBA window, click tools - references
Check atpvbaen.xls

Then, you don't use the Application or Worksheet function object..
This only applies if you're using Excel 2003 or older, which we don't know because you never told us. The WORKDAY function is built into Excel and VBA without any references in Excel 2007+, and you do use "Application.WorksheetFunction.Workday..."
 
Upvote 0

Forum statistics

Threads
1,216,477
Messages
6,130,862
Members
449,600
Latest member
inborntarmac

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top