Could any body help me to find 1st working day in the month.

Eric Penfold

Active Member
Joined
Nov 19, 2021
Messages
424
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
This code finds first day in month but i need first working day i.e. 02/04 at the moment it returns 01/04.

VBA Code:
Function fwday(Optional givenDate As Variant) As Date

    Dim d As Date

    If IsMissing(givenDate) Then givenDate = Date

    d = DateSerial(Year(givenDate), Month(givenDate), 1)
    d = d + ((9 - (d Mod 7)) Mod 7)
    fwday = d
    
End Function
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
The code below seems to work. Managed to work it out myself.

VBA Code:
Option Explicit

Sub FillDates()

Dim wb As Workbook
Dim ws As Worksheet
Dim FCell As Range
Dim LCell As Range
Dim LRow   As Long

Set wb = Workbooks("DailyMail.xlsx")
Set ws = wb.Worksheets("Daily Mail Update")
Set FCell = ws.Range("A2")
Set LCell = ws.Range("A2" & LRow)
LRow = ws.Cells(Rows.Count, 1).End(xlUp).Row

If Not Date = Application.WorkDay(DateSerial(Year(Date), Month(Date), 0), 1) Or _
    Date = Application.WorkDay(DateSerial(Year(Date), Month(Date), 0), 2) Then
    
FCell.Clear

FCell = Evaluate("Workday(EOMonth(Now(),-1),1)")
   
With FCell
    .HorizontalAlignment = xlCenter
    .NumberFormat = ("dd/mm/yy")
End With

End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,216,005
Messages
6,128,231
Members
449,435
Latest member
Jahmia0616

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