Moving end of the month

Rainmanne

Board Regular
Joined
Mar 10, 2016
Messages
120
Office Version
  1. 2013
Platform
  1. Windows
I am trying to get a formula for the month's end on any particular day (TODAY) but can't get my head around it.

Basically, end of the month is 24th, unless 25th falls on the weekend. So if the 25th is Saturday, EOM is 23rd and if it is Sunday, then 22nd.

I can build an IF structure for the date, it is not difficult:

Code:
=IF(WEEKDAY(DATE(YEAR(B2),MONTH(B2),25),2)=6,DATE(YEAR(B2),MONTH(B2),23),IF(WEEKDAY(DATE(YEAR(B2),MONTH(B2),25),2)=7,DATE(YEAR(B2),MONTH(B2),22),DATE(YEAR(B2),MONTH(B2),24)))

Where B2 is TODAY(). Probably not very elegant, but it works.

However, I cannot figure out how to change a month, because the end date is different in each particular month. For example in February this year, end of the month should be 22/02/2018 up to this date and 22/03/2018 from 23/02/2018 till 22/03/2018. After that it should change to 24/04/2018. But I cannot figure out how to make the change.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I think you want to use
=DATE(YEAR(B2),IF(DAY(B2)>24,1,0)+MONTH(B2),24)-MAX(WEEKDAY(DATE(YEAR(B2),IF(DAY(B2)>24,1,0)+MONTH(B2),24)-1)-5,0)

Where B2 is any date
 
Upvote 0
I think you want to use
=DATE(YEAR(B2),IF(DAY(B2)>24,1,0)+MONTH(B2),24)-MAX(WEEKDAY(DATE(YEAR(B2),IF(DAY(B2)>24,1,0)+MONTH(B2),24)-1)-5,0)

Where B2 is any date
Thanks a lot. Unfortunately it does not handle the date and teh change of the month properly. For example, on 21/02/2016 the end of the month should be 22/02/2018 as Feb 25 is Sunday, but the formula shows 23/02/2018. On 23/02/2018 and beyond it should be 22/03/2018 (again March 25 is Sunday) but it shows 23/02/2018 for 22nd and 23rd of Feb and 23/03/2018 for the rest of the month.
 
Upvote 0
Try this

=DATE(YEAR(B2),MONTH(B2),24)-IF(WEEKDAY(DATE(YEAR(B2),MONTH(B2),24),2)=5,1,IF(WEEKDAY(DATE(YEAR(B2),MONTH(B2),24),2)=6,2,0))

DateEOM
23-02-201822-02-2018
24-03-201822-03-2018
22-04-201824-04-2018
21-05-201824-05-2018
19-06-201824-06-2018
18-07-201824-07-2018
16-08-201823-08-2018

<colgroup><col><col></colgroup><tbody>
</tbody>
 
Last edited:
Upvote 0
Sorry, let me clarify:

Let's take March. 25th is Sunday, so the last day of the month should be 22nd. The new month starts on 23rd then. In April, 25th is Wednesday, so the last day of the month should be 24th.

TODAY EOM
20/03/2018 22/03/2018
21/03/2018 22/03/2018
22/03/2018 22/03/2018
23/03/2018 24/04/2018
24/03/2018 24/04/2018
 
Last edited:
Upvote 0
This is what I have after plugging in the formula from the last post:

TODAY EOM
20/02/2018 22/02/2018
21/02/2018 22/02/2018
22/02/2018 22/02/2018
23/02/2018 22/02/2018
24/02/2018 22/02/2018
25/02/2018 22/02/2018
26/02/2018 22/02/2018
27/02/2018 22/02/2018
28/02/2018 22/02/2018
01/03/2018 22/03/2018
 
Upvote 0
See if this works for you:

=SUMPRODUCT(IF(B2>EOMONTH(B2,-1)+24-LOOKUP(WEEKDAY(EOMONTH(B2,-1)+25,16),{1;2;3},{1;2;0}),{0,1},{1,0}),EOMONTH(B2,{-1,0})+24-LOOKUP(WEEKDAY(EOMONTH(B2,{-1,0})+25,16),{1;2;3},{1;2;0}))
 
Upvote 0
Solution

Forum statistics

Threads
1,215,338
Messages
6,124,356
Members
449,155
Latest member
ravioli44

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