VBA Workday negative days problem

Status
Not open for further replies.

cortexnotion

Board Regular
Joined
Jan 22, 2020
Messages
150
Office Version
  1. 2013
Platform
  1. Windows
Please ignore, I figured out I had a corrupt date value in the column

Evening All

I'm having a strange problem with Workday in VBA. If the date difference goes below -44 the error message "unable to get the WorkDay property of the WorksheetFunction class" pops up. I've experimented with putting all values above -45 and the correct results are pasted back to the sheet. Any ideas?

Thanks!

VBA Code:
Sub TrackerData()

Dim DataInAry As Variant, DataOutAry As Variant,Hols As Variant, LR1 As Long, a As Long, b As Long,

LR1 = ThisWorkbook.Sheets("ProjWork").Range("D" & Rows.Count).End(xlUp).Row
DataInAry = ThisWorkbook.Sheets("ProjWork").Range("A3:I" & LR1).Value
Hols = Array("01/01/2021", "02/04/2021")

ReDim DataOutAry(1 To LR1, 1 To 9)
b = 1
For a = LBound(DataInAry) To UBound(DataInAry)
    If InStr(DataInAry(a, 1), "TCS") = 0 Then
        DataOutAry(b, 1) = WorksheetFunction.WorkDay(DataInAry(a, 9), -10, Hols)
        DataOutAry(b, 2) = WorksheetFunction.WorkDay(DataInAry(a, 9), -21, Hols)
        DataOutAry(b, 3) = WorksheetFunction.WorkDay(DataInAry(a, 9), -41, Hols)
        DataOutAry(b, 4) = WorksheetFunction.WorkDay(DataInAry(a, 9), -52, Hols)
        DataOutAry(b, 5) = WorksheetFunction.WorkDay(DataInAry(a, 9), -67, Hols)
        DataOutAry(b, 6) = WorksheetFunction.WorkDay(DataInAry(a, 9), -78, Hols)
        DataOutAry(b, 7) = WorksheetFunction.WorkDay(DataInAry(a, 9), -81, Hols)
        DataOutAry(b, 8) = WorksheetFunction.WorkDay(DataInAry(a, 9), -107, Hols)
        DataOutAry(b, 9) = WorksheetFunction.WorkDay(DataInAry(a, 9), -122, Hols)
    b = b + 1
    End If
Next a
ThisWorkbook.Sheets("ProjWork").Range("N3:V3").Resize(UBound(DataOutAry)).Value = DataOutAry
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Status
Not open for further replies.

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

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