I’ve been trying to implement the Workday Function in VBA. The function works fine when I implement it manually in Excel, however, once I translate it to VBA I run into an error. The cell range B1:B5 contains given holidays as dates. Whenever I try to add the holidays to the workday function, I get the following error: “Unable to get the WorkDay property of the WorksheetFunction class”.
Sub WorkdayMacro()
Dim PaymDate As Date
Dim holidays As Range
PaymDate = .Range("First_Payment_Date").Value
Set holidays = .Range("B1:B5")
Dim row As Long
row = 5
If Application.WorksheetFunction.WorkDay(Application.WorksheetFunction.EDate(PaymDate, i) - 1, 1, holidays) = Application.WorksheetFunction.EDate(PaymDate, i) Then
.Range("A" & row).Value = Application.WorksheetFunction.EDate(PaymDate, i)
Else
.Range("A" & row).Value = Application.WorksheetFunction.WorkDay(Application.WorksheetFunction.EDate(PaymDate, i), 1, holidays)
End If
End Sub
I’ve tried changing the holidays to a single date or omitting them, then the function works fine, so I’m guessing that my problem has to do with how I store the data. Unfortunately, I cannot find anything online that could help me solve this problem. I would appreciate any hints.
mathi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.