First working day of the previous month

a_mahey

Board Regular
Joined
Dec 2, 2014
Messages
51
Hello all,

Can someone help in defining a VBA variable which will return a date which will be the first working date of the last month. So for example, today's date is 01/06/2015 but I want the variable to return based on today's date the first working day of last month which is 01/05/2015 which was a Friday.

many thanks in advance
 

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Momentman

Well-known Member
Joined
Jan 11, 2012
Messages
4,066
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
<b>Excel 2013</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #BBB"><colgroup><col width="25px" style="background-color: #DAE7F5" /><col /><col /></colgroup><thead><tr style=" background-color: #DAE7F5;text-align: center;color: #161120"><th></th><th>A</th><th>B</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style="text-align: right;;">01-Jun-15</td><td style="text-align: right;;">01-May-15</td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style="text-align: right;;">01-Jul-15</td><td style="text-align: right;;">01-Jun-15</td></tr><tr ><td style="color: #161120;text-align: center;">3</td><td style="text-align: right;;">01-Dec-15</td><td style="text-align: right;;">02-Nov-15</td></tr></tbody></table><p style="width:3.6em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #BBB;border-top:none;text-align: center;background-color: #DAE7F5;color: #161120">Sheet5</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: #FFFFFF" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: #FFFFFF;border-collapse: collapse; border-color: #BBB"><thead><tr style=" background-color: #DAE7F5;color: #161120"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: #DAE7F5;color: #161120">B1</th><td style="text-align:left">=WORKDAY(<font color="Blue">EOMONTH(<font color="Red">A1,-2</font>),1</font>)</td></tr></tbody></table></td></tr></table><br />
 

a_mahey

Board Regular
Joined
Dec 2, 2014
Messages
51
thanks a lot - could you please help to define it in VBA.

Regards
 

Momentman

Well-known Member
Joined
Jan 11, 2012
Messages
4,066
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
thanks a lot - could you please help to define it in VBA.

Regards
Maybe
<b>Excel 2013</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #BBB"><colgroup><col width="25px" style="background-color: #DAE7F5" /><col /><col /></colgroup><thead><tr style=" background-color: #DAE7F5;text-align: center;color: #161120"><th></th><th>A</th><th>B</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style="text-align: right;;">01-Jun-15</td><td style=";">01/05/2015</td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style="text-align: right;;">01-Jul-15</td><td style=";">01/06/2015</td></tr><tr ><td style="color: #161120;text-align: center;">3</td><td style="text-align: right;;">01-Dec-15</td><td style=";">02/11/2015</td></tr></tbody></table><p style="width:3.6em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #BBB;border-top:none;text-align: center;background-color: #DAE7F5;color: #161120">Sheet7</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: #FFFFFF" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: #FFFFFF;border-collapse: collapse; border-color: #BBB"><thead><tr style=" background-color: #DAE7F5;color: #161120"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: #DAE7F5;color: #161120">B1</th><td style="text-align:left">=FirstWrkDay(<font color="Blue">A1</font>)</td></tr></tbody></table></td></tr></table><br />
and the UDF is
Code:
]
Function FirstWrkDay(sedate As Date)
    Application.Volatile
    Dim wf As WorksheetFunction
    Set wf = Application.WorksheetFunction
    FirstWrkDay = Format(wf.WorkDay(wf.EoMonth(sedate, -2), 1), "dd/mm/yyyy")
End Function
 

Watch MrExcel Video

Forum statistics

Threads
1,122,521
Messages
5,596,648
Members
414,083
Latest member
Mrsash

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
Top