Excel VBA Workday Function: Step-by-Step Guide
In this article
The Excel VBA Workday function returns a date that is a specified number of working days before or after a start date, excluding weekends and any holidays you list. It is the VBA equivalent of the worksheet WORKDAY function and is useful for building due dates, project schedules, or delivery estimates directly in your macros. To use it, you need Excel (any modern version) and a basic understanding of how to open the VBA editor and write a simple macro.
What You'll Need
- Excel 2010 or later (the Workday function is available in all recent versions).
- Access to the Visual Basic Editor (Alt + F11 on Windows, or the Developer tab).
- A list of holiday dates if you want to exclude them (optional but recommended for accuracy).
Step-by-Step
- Open the VBA editor. Press Alt + F11 (Windows) or Fn + Alt + F11 (Mac). The editor opens in a separate window.
- Insert a new module. In the editor, go to Insert > Module. A blank code window appears.
- Write a basic Workday call. Type the following macro to see the result in a message box:
This returns the date 10 working days after January 1, 2025, skipping weekends.Sub ShowWorkday() Dim result As Date result = Application.WorksheetFunction.Workday("1/1/2025", 10) MsgBox result End Sub - Add holidays (optional). To exclude specific dates, provide a range or an array as the third argument. For example, if holidays are in A1:A5 on Sheet1:
You can also use an array:result = Application.WorksheetFunction.Workday("1/1/2025", 10, Range("A1:A5"))Array(#1/1/2025#, #12/25/2025#). - Use a cell value as the start date. Instead of a literal string, reference a cell:
Range("B1").ValueorRange("B1")if the cell contains a date. Ensure the cell is formatted as a date. - Run the macro. Press F5 while the cursor is inside the subroutine, or go to Run > Run Sub/UserForm. A message box shows the calculated date.
- Write the result to a cell. Replace MsgBox with an assignment:
Range("C1").Value = result. This places the date in cell C1. - Handle errors. If the start date is invalid or the holidays range is not valid, VBA raises an error. Use
On Error Resume Nextor check inputs before calling the function.
Common Mistakes
- Forgetting to use Application.WorksheetFunction. In VBA, Workday is not a built-in VBA function; you must call it through WorksheetFunction or use the Analysis ToolPak equivalent (not needed in modern Excel).
- Passing holidays as a single date instead of an array or range. The third argument expects a list of dates, not one date. Use
Array(#12/25/2025#)for a single holiday. - Using text strings for dates without proper formatting. VBA may interpret "1/2/2025" differently depending on regional settings. Use
DateSerial(2025, 1, 2)to avoid ambiguity. - Assuming Workday includes the start date. The function counts working days after the start date; the start date itself is not counted as a working day unless it is a working day and you use a negative number.
- Ignoring that holidays must be actual dates. If your holiday range contains text or blanks, the function may return unexpected results or errors.
Tips
- Use
DateSerialto build dates unambiguously:DateSerial(2025, 12, 25). - Store your holiday list in a named range (e.g., "Holidays") and reference it as
Range("Holidays")for cleaner code. - To find a date a certain number of workdays before a start date, use a negative number for the days argument.
- Combine Workday with
Formatto display the result as text:MsgBox Format(result, "dd-mmm-yyyy"). - If you need to calculate working days between two dates, use
Application.WorksheetFunction.NetworkDaysinstead.
Troubleshooting
If the function returns a date that seems off, check that your holidays range does not include the start date or weekends (weekends are already excluded). If you get a "Type mismatch" error, ensure the start date is a valid date or a cell containing a date, and that holidays are passed as a range or array of dates. If the function is not available, make sure you are using Excel 2010 or later; in older versions, you may need to enable the Analysis ToolPak. If the result is a serial number instead of a date, format the cell as a date (Home > Number Format > Short Date).
Frequently Asked Questions
Does the Workday function include the start date?
No, it counts working days after the start date. The start date is not counted as a working day unless you use a negative number and the start date is a working day.
Can I use Workday with a cell reference for the start date?
Yes, pass the cell value or the range object: Range("A1").Value or Range("A1").
What happens if a holiday falls on a weekend?
Weekends are already excluded, so holidays on weekends have no additional effect. Only holidays that fall on working days are skipped.
Is Workday available in all Excel versions?
Yes, in Excel 2010 and later it is a built-in worksheet function. In Excel 2007 and earlier, you may need to enable the Analysis ToolPak.
How do I exclude only specific holidays?
Provide a range or array of those holiday dates as the third argument. Only those dates are excluded in addition to weekends.
Can I use Workday to calculate a date before a start date?
Yes, use a negative number for the days argument. For example, Workday("1/31/2025", -5) returns the date 5 working days before January 31, 2025.