Workday in VBA

chris54

New Member
Joined
Aug 23, 2023
Messages
8
Office Version
  1. 365
Platform
  1. Windows
I want to add 30 weekdays to a date instead of 30 days as is in my existing code but can't quite figure it out. I've set up the following:

VBA Code:
Sub WhyWork()
Dim d1 As Date, wf As WorksheetFunction
Set wf = Application.WorksheetFunction
d2 = wf.WorkDay(Date, 30)
End Sub

But I need to insert somewhere into:

VBA Code:
ActiveSheet.Select
     
    Range("L3").Select
    Selection.AutoFilter
    Cells.Select
    Range("I1").Activate
    Selection.EntireColumn.Hidden = False
    Columns("E:E").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("AZ1").Select
    ActiveSheet.Paste
    Range("AZ3").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "Billing Trx Date"
    Columns("Q:Q").Select
    Selection.Copy
    Range("BA1").Select
    ActiveSheet.Paste
    Range("BA3").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "Billing Due Date"
    
       Billdate = Application.InputBox("Enter 1st day of Current Month Billing  eg 01-Jan-2015")
       StartTRX = "<" & Billdate ' 01/10/15
       EndTRX = Application.EoMonth(Billdate, 0) '31/10/15
       EndTRX = ">" & EndTRX
        
       StartDue = Application.EoMonth(Billdate, 0)  ' 30/11/15
       
       EndDue = Application.EoMonth(Billdate, 1) ' 31/10/15
       StartDue = "<=" & StartDue ' due date
       EndDue = ">" & EndDue ' due date =
    
    
    Range("AZ3").Select
    Selection.AutoFilter
    Range("BC1").Select
    ActiveSheet.Range("$A$3:$BA$70000").AutoFilter Field:=52, Criteria1:= _
        StartTRX, Operator:=xlOr, Criteria2:=EndTRX
    Range("AZ4").Select
    Range(Selection, Selection.End(xlDown)).Select
    'Range("AZ122").Select
    'Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    ActiveSheet.Range("$A$3:$BA$70000").AutoFilter Field:=52
    ActiveSheet.Range("$A$3:$BA$70000").AutoFilter Field:=53, Criteria1:= _
        StartDue, Operator:=xlOr, Criteria2:=EndDue
    Range("BA4").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    ActiveSheet.Range("$A$3:$BA$70000").AutoFilter Field:=53
    Range("AZ4").Select
    pivots
    
End Sub


Any suggestions?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I would recommend making "WhyWork" a function instead of a procedure, i.e.
VBA Code:
Function WhyWork(startDate as Date, numDays as Long) as Date
    WhyWork = Application.WorksheetFunction.WorkDay(startDate, numDays)
End Sub

Then you can call it like any other function in your code, i.e.
VBA Code:
MyDate = WhyWork(Date,30)
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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