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