How to Get Last Day of Previous Month in Excel (3 Methods)

 

The sample dataset contains a list of dates in column B. We’ll find the last day of the previous month in column C.

3 Different Methods to Get Last Day of Previous Month in Excel


Method 1 – Excel EOMONTH Function to Find the Last Day of the Previous Month

➧ Syntax:

The syntax for the EOMONTH function is:

EOMONTH(start_date, months)

Excel EOMONTH Function to Find Last Day of Previous Month

➧ Arguments:

start_date: [required] The starting date is represented by this date.

months: [required] The number of months between the start date and end date.

Steps:

  • Select the cell where you want to get the last day of the previous month. We chose cell C5.
  • Use the following formula.
=EOMONTH(B5,-1)

Excel EOMONTH Function to Find Last Day of Previous Month

  • Press the Enter key.
  • The formula shows a 5-digit number instead of a date, because Excel saves it as a time offset from Jan 1, 1900.
  • Click on the result cell.
  • Select Short Date under the Number category on the Home tab.

Excel EOMONTH Function to Find Last Day of Previous Month

  • Drag the Fill Handle down to copy the formula and formatting over the range.

  • Here are the results for our sample.

Excel Last Day of Previous Month

Read More: How to Calculate First Day of Previous Month in Excel 


Method 2 – Detect the Last Day of the Previous Month with the Excel DATE Function

Steps:

  • Choose the cell where you wish to get the last day of the previous month. We selected cell C5.
  • Use the following formula in the cell.
=DATE(YEAR(B5),MONTH(B5),0)

Detect the Last Day of Previous Month with Excel DATE Function

  • Hit the Enter key.Detect the Last Day of Previous Month with Excel DATE Function

How Does the Formula Work?

YEAR(B5) returns the year of the date in cell B5.

Output → 2022

MONTH(B5) returns the month of the date in cell B5.

Output → 3

DATE(YEAR(B5), MONTH(B5),0) returns the previous month’s last day of the specific date in cell B5.

Output → 28-02-2022

  • Drag the Fill Handle down to duplicate the formula.

  • Here are the results.


Method 3 – Excel VBA to Get the Last Day of the Previous Month in Excel

We have today’s date in cell B5, which is 21 March 2022. We want to get the last day of the previous month in a MsgBox.

Steps:

  • Go to the Developer tab on the ribbon.
  • Click on Visual Basic or press Alt + F11 to open the Visual Basic Editor.

Excel VBA to Get Last Day of Previous Month in Excel

  • Alternatively, right-click on the sheet name and select View Code.

Excel VBA to Get Last Day of Previous Month in Excel

  • This will open the Visual Basic Editor where you can write the code.
  • Insert the VBA code below into the editor.

VBA Code:

Sub Last_Day_of_Previous_Month()
Dim TodaysDate As Date
TodaysDate = Range("B5")
LastDay = DateSerial(Year(TodaysDate), Month(TodaysDate), 1) - 1
MsgBox LastDay
End Sub
  • Run the code by clicking the Run Sub button or pressing the F5 key.

  • This will open a MsgBox and show the last day of the previous month.

Read More: Excel Formula for Current Month and Year


Download the Practice Workbook


Related Articles


<< Go Back to Excel MONTH Function | Excel Functions | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Sabrina Ayon
Sabrina Ayon

Sabrina Ayon, a Computer Science and Engineering graduate from United International University, has been an integral part of the ExcelDemy project for two years. She authored 150+ articles, excelling in instructing through visually engaging Excel tutorials. With a passion for teaching, Sabrina conducted sessions on Excel VBA, sharing her knowledge and insights with others. Currently holding the position of Project Manager for the ExcelDemy Visual Development Project, she oversees various aspects of the project, ensuring its smooth operation... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo