Return the First or Last Day of a Month in Excel Using a Condition
Question details
Return the first day of the month for the first date when a condition is met, and the last day of the month for other dates.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A worksheet contains dates and a condition that determines whether the first date should use the start of its month.
- Observed behavior
- The desired results are the first day of the month for the qualifying first date and month-end dates for all other entries.
Make sure the source cells contain valid Excel dates. In the examples below, dates begin in B9 and the condition is in F6; adjust these references to match your worksheet.
Use a row-based formula for the first date in the list
Use this formula when the first date is in a known row and you want to fill the formula down.
In an empty result cell on row 9, such as C9, enter =IF(ROW(B9)>9,EOMONTH(B9,0),IF($F$6="AR",DATE(YEAR(B9),MONTH(B9),1),EOMONTH(B9,0))).
Drag the fill handle from C9 down alongside the dates in column B. If your data starts on another row, change both B9 and the number 9 in the formula to that starting row.
Select the result cells and choose a date format from Home > Number Format so the results appear as dates rather than serial numbers.

Use a dynamic array formula to find the earliest date
Use this approach in a version of Excel that supports dynamic arrays when the earliest date should be found automatically.
Return conditional month start or end dates in WPS Spreadsheets
Use the row-based IF and EOMONTH formula in WPS Spreadsheets to calculate the appropriate month boundary for each date.
- 1. Open your workbook: Open WPS Spreadsheets and use Open to select your Excel workbook.
- 2. Enter the formula: With dates starting in B9 and the condition in F6, enter =IF(ROW(B9)>9,EOMONTH(B9,0),IF($F$6="AR",DATE(YEAR(B9),MONTH(B9),1),EOMONTH(B9,0))) in C9.
- 3. Fill and format the results: Drag the fill handle down column C, then select the results and choose a date format from the Home tab.

Frequently Asked Questions
What does the AR condition do in these formulas?
The formulas check whether F6 equals "AR". If it does, the qualifying first date returns its month's first day; otherwise, it returns the month's last day.
How do I change the formula if my dates start in row 12?
In the row-based formula, replace B9 with B12 and change the row comparison from >9 to >12. Enter the formula in a result cell on row 12, then fill it down.
Why do my results appear as numbers instead of dates?
Excel stores dates as serial numbers. Select the result cells and choose a date format from Home > Number Format.
What happens if the earliest date appears twice?
The dynamic array formula returns the first day of the month for every occurrence of the minimum date when F6 is AR. Use the row-based formula if only the starting row should receive that result.




