3 weekdays or more in a week relates to same month

atearth

New Member
Joined
Feb 25, 2015
Messages
39
Office Version
  1. 365
  2. 2013
  3. 2007
Platform
  1. Windows
  2. Web
If a week has 3 or more weekdays in it, the first the same month is shown in the next cell? What formula can I use to show this?

Example dates
31-Jan-17 would show 01-Feb-17.
31-Jan-18 would show 01-Jan-18.
01-Sep-21 would show 01-Sep-21.
01-Sep-22 would show 01-Aug-22.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Came out a very extensive formula

=IF(WEEKDAY(A1,2)=1,IF(AND(MONTH(A1+1)=MONTH(A1),MONTH(A1+2)=MONTH(A1)),A1-DAY(A1)+1,EOMONTH(A1,0)+1),
IF(WEEKDAY(A1,2)=2,IF(OR(AND(MONTH(A1-1)=MONTH(A1),MONTH(A1+1)=MONTH(A1)),AND(MONTH(A1+1)=MONTH(A1),MONTH(A1+2)=MONTH(A1))),A1-DAY(A1)+1,EOMONTH(A1,0)+1),
IF(WEEKDAY(A1,2)=3,IF(OR(AND(MONTH(A1-1)=MONTH(A1),MONTH(A1+1)=MONTH(A1)),AND(MONTH(A1+1)=MONTH(A1),MONTH(A1+2)=MONTH(A1)),AND(MONTH(A1-1)=MONTH(A1),MONTH(A1-2)=MONTH(A1))),A1-DAY(A1)+1,EOMONTH(A1,0)+1),
IF(WEEKDAY(A1,2)=4,IF(OR(AND(MONTH(A1-1)=MONTH(A1),MONTH(A1+1)=MONTH(A1)),AND(MONTH(A1-2)=MONTH(A1),MONTH(A1-1)=MONTH(A1))),A1-DAY(A1)+1,EOMONTH(A1,0)+1),
IF(WEEKDAY(A1,2)=5,IF(AND(MONTH(A1-1)=MONTH(A1),MONTH(A1-2)=MONTH(A1)),A1-DAY(A1)+1,EOMONTH(A1,0)+1))))))
 
Last edited:
Upvote 0
O run this macro.
Assume that the data starts in cell A1

Code:
Sub Macro12()
    With Range("B1:B" & Range("A" & Rows.Count).End(xlUp).Row)
        .FormulaR1C1 = _
        "=IF(WEEKDAY(RC[-1],2)=1,IF(AND(MONTH(RC[-1]+1)=MONTH(RC[-1])," & _
        "MONTH(RC[-1]+2)=MONTH(RC[-1])),RC[-1]-DAY(RC[-1])+1,EOMONTH(RC[-1],0)+1)," & Chr(10) & _
        " IF(WEEKDAY(RC[-1],2)=2,IF(OR(AND(MONTH(RC[-1]-1)=MONTH(RC[-1])," & _
        "MONTH(RC[-1]+1)=MONTH(RC[-1])),AND(MONTH(RC[-1]+1)=MONTH(RC[-1])," & _
        "MONTH(RC[-1]+2)=MONTH(RC[-1]))),RC[-1]-DAY(RC[-1])+1,EOMONTH(RC[-1],0)+1)," & Chr(10) & _
        " IF(WEEKDAY(RC[-1],2)=3,IF(OR(AND(MONTH(RC[-1]-1)=MONTH(RC[-1])," & _
        "MONTH(RC[-1]+1)=MONTH(RC[-1])),AND(MONTH(RC[-1]+1)=MONTH(RC[-1])," & _
        "MONTH(RC[-1]+2)=MONTH(RC[-1])),AND(MONTH(RC[-1]-1)=MONTH(RC[-1])," & _
        "MONTH(RC[-1]-2)=MONTH(RC[-1]))),RC[-1]-DAY(RC[-1])+1,EOMONTH(RC[-1],0)+1)," & Chr(10) & _
        " IF(WEEKDAY(RC[-1],2)=4,IF(OR(AND(MONTH(RC[-1]-1)=MONTH(RC[-1])," & _
        "MONTH(RC[-1]+1)=MONTH(RC[-1])),AND(MONTH(RC[-1]-2)=MONTH(RC[-1])," & _
        "MONTH(RC[-1]-1)=MONTH(RC[-1]))),RC[-1]-DAY(RC[-1])+1,EOMONTH(RC[-1],0)+1)," & Chr(10) & _
        " IF(WEEKDAY(RC[-1],2)=5,IF(AND(MONTH(RC[-1]-1)=MONTH(RC[-1])," & _
        "MONTH(RC[-1]-2)=MONTH(RC[-1])),RC[-1]-DAY(RC[-1])+1,EOMONTH(RC[-1],0)+1))))))"
        .Value = .Value
    End With
End Sub
 
Upvote 0
Or try:

=DATE(YEAR(A1),MONTH(A1-WEEKDAY(A1)+4),1)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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