3 weekdays or more in a week relates to same month

atearth

New Member
Joined
Feb 25, 2015
Messages
27
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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,619
Office Version
  1. 2007
Platform
  1. Windows
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:

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,619
Office Version
  1. 2007
Platform
  1. Windows
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
 

Phuoc

Active Member
Joined
Apr 29, 2016
Messages
320
Or try:

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

Watch MrExcel Video

Forum statistics

Threads
1,129,362
Messages
5,635,832
Members
416,885
Latest member
hs11

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