Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel Formula for End of Previous Month

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

You can calculate the date of the last day of the previous month using the EOMONTH function, which is the most reliable method. Alternatively, you can use a combination of the DATE function and the YEAR and MONTH functions to get the same result without using a dedicated date function. A third method involves using the EOMONTH function with a negative one as the second argument, which is often the most concise syntax to remember.

What You'll Need

  • A computer with Microsoft Excel installed (2021, 365, or older versions).
  • The data you wish to analyze, typically a column of dates.
  • A basic understanding of relative and absolute cell references (optional, but helpful).

Step-by-Step

  1. Locate an empty cell. Click on any cell in your spreadsheet where you want the result of the formula to appear. This cell is often in the same row as a date you are referencing, or in a dedicated "Calculations" column.
  2. Enter the main formula. Type one of the following formulas into the cell you selected. The formula syntax is =EOMONTH(start_date, months).
  3. Option A: The EOMONTH shortcut (Easiest). To get the end of the previous month from a specific date, use this formula: =EOMONTH(A2, -1) In this example, A2 is the cell containing the date. The number -1 tells Excel to go back one month from the date in A2.
  4. Option B: The DATE function (Works in all versions). If you are using an older version of Excel that does not support EOMONTH, or you prefer to build the date manually, use this formula: =DATE(YEAR(A2), MONTH(A2)-1, 1) This formula takes the year from A2, subtracts one from the month in A2, and sets the day to 1. Excel automatically rolls the date back to the last day of the new month. For example, if A2 is January 15, 2023, this formula calculates the date for December 1, 2022, and Excel displays it as December 31, 2022.
  5. Option C: The YEAR and MONTH functions (Alternative). You can also use a similar logic to Option B but written slightly differently. This method explicitly calculates the year and month before the current one: =DATE(YEAR(A2)-IF(MONTH(A2)=1,1,0), MONTH(A2)-IF(MONTH(A2)=1,12,1), 1) This is more complex and prone to errors in manual entry, but it demonstrates the logic of subtracting a month from a year when you cross over the December/January boundary. Option B is strongly preferred for its simplicity.
  6. Fill down the formula. Once the formula is working in your first cell, you can apply it to the rest of your data. Hover your mouse over the bottom-right corner of the cell until you see a small square handle. Click and drag this handle down to copy the formula to the other rows. Excel will automatically adjust the cell references (e.g., A2 becomes A3, A4, etc.).
  7. Format the result. By default, Excel might display the result as a serial number (e.g., 45168). To see it as a readable date, right-click the cell, select Format Cells from the context menu, choose Date on the left, and select a preferred format from the list on the right, such as March 31, 2023. Click OK.

Common Mistakes

  • Forgetting the negative sign. In the EOMONTH function, the second argument is the number of months to move. If you type =EOMONTH(A2, 1), you will get the end of the following month, not the previous one. Always use -1 to go back.
  • Using EOMONTH in older Excel versions. The EOMONTH function was introduced in Excel 2007. If you are working in an extremely old version (from the 2003 era or earlier), this function will result in a #NAME? error. In those cases, you must use the DATE function method described in Step 2, Option B.
  • Incorrect cell references. When dragging the formula down, ensure your original date reference is in a relative cell (like A2) and not an absolute one (like $A$2). If you use an absolute reference, the formula will always calculate the end of the previous month for the date in cell A2, regardless of which row it is pasted into.
  • Assuming the result is always a month. The result of these formulas is always a specific date. It is not a month number or a year number. If you need to extract the month name (e.g., "December"), you must wrap the result in the TEXT function, like =TEXT(EOMONTH(A2,-1), "MMMM").

Tips

  • Use EOMONTH for conditional calculations. You can nest the EOMONTH formula inside an IF function to create dynamic reports. For example, to calculate a value only if the date is in the previous month, you could use: =IF(A2 > EOMONTH(TODAY(), -1), "Yes", "No"). This checks if the date in A2 is later than the end of the last month.
  • Combine with TODAY() for dynamic reporting. To always show the end of the previous month relative to the current date (not a fixed date in a cell), use =EOMONTH(TODAY(), -1). This is perfect for monthly summaries or dashboards that update automatically.
  • Check for error values. If you see a #VALUE! error, it usually means one of the arguments in your formula (like the start_date) is not a valid date format. Check to ensure the cell contains a date and not text that looks like a date.
  • Consistent date formats. Before applying these formulas to a large dataset, ensure all your source dates are in a consistent format. If some dates are text and some are real dates, the formula will fail on the text entries.

Troubleshooting

If your formula returns an error or an incorrect result, follow these steps to diagnose the issue.

Issue: The formula returns a #NAME? error.

Diagnosis: This indicates that Excel does not recognize the function name you typed. As mentioned in Common Mistakes, this is most common in Excel 2003 and earlier.

Fix: Switch to the DATE function method. Use =DATE(YEAR(A2), MONTH(A2)-1, 1) instead of =EOMONTH(A2, -1). This method is supported in all versions of Excel.

Issue: The formula returns a #VALUE! error.

Diagnosis: This error appears when a function expects a number or a date, but receives text or a non-numerical value instead.

Fix: Check the cell you are referencing (e.g., A2). Ensure it is formatted as a Date. If it is a number, it might be a serial number representing a date, which is fine. If it is text, you may need to convert it. You can try using the VALUE function to convert it, or re-enter the date by double-clicking the cell and pressing Enter.

Issue: The result is a serial number (like 45168) instead of a date.

Diagnosis: Excel has calculated the date correctly, but the cell formatting is set to "General" or "Number".

Fix: Select the cell with the serial number. Right-click and choose Format Cells. Go to the Number tab. Select Date from the list on the left and choose a format from the right. Click OK. The number will now display as a readable date.

Issue: The result is incorrect (e.g., for January, it returns January 31 instead of December 31).

Diagnosis: This is a common issue with the DATE function method if the logic for handling year rollover is not perfect. However, the standard =DATE(YEAR(A2), MONTH(A2)-1, 1) logic is correct. This error often occurs because the user is using the EOMONTH function but with a positive number, or they are using the DATE function but the year calculation is flawed.

Fix: Re-verify your formula. For the EOMONTH function, ensure the second argument is -1. For the DATE function, ensure you are subtracting 1 from the month. If you are using a custom complex formula, it may be missing the IF statement to handle the year rollover (e.g., IF(MONTH(A2)=1, YEAR(A2)-1, YEAR(A2))). The EOMONTH function handles this rollover automatically, so it is the preferred method.

Frequently Asked Questions

  1. Why does EOMONTH return a #VALUE! error? This error occurs when the start_date argument is not a valid date. Ensure the cell contains a date and not text. You can verify this by trying to change the cell's format to 'General' and seeing if it becomes a number (like 45000). If it remains text, the cell is not recognized as a date by Excel.
  2. Can I use this formula to get the last day of the current month? Yes. To get the end of the current month, you can use =EOMONTH(TODAY(), 0). The number 0 tells Excel to stay in the same month as the reference date.
  3. Does this work in Google Sheets? Yes, both the EOMONTH and DATE functions are supported in Google Sheets. The syntax is identical.
  4. What if I want the end of the month two months ago? Simply change the number in the second argument to -2. The formula would be =EOMONTH(A2, -2).
  5. How do I get the name of the previous month (e.g., "December")? Wrap the formula in the TEXT function. For example: =TEXT(EOMONTH(A2,-1), "MMMM"). This will return the text string "December".
  6. Why is the EOMONTH function different in different languages? While the logic is the same, the function name varies by language. In French, it is FIN.MOIS, and in German, it is ENDMONAT. However, the syntax and arguments remain consistent.