Excel自动填充指定月份31日及月度日期模板制作技术问询
Hey there! Let's tackle this date-filling issue for your senior staff's spreadsheet template—super thoughtful that you're making this easier for them. Here's a solid solution to auto-fill the full month (including 31-day months) and weekdays just by entering the first day of the month:
Step 1: Set Up the Input Cell
Pick a dedicated cell (e.g., A1) as the input field for the first day of the month. Instruct your team to enter a date like 2024-06-01 here.
Step 2: Generate Dynamic Date Sequence (Works for All Month Lengths)
In the cell where you want the first date to appear (e.g., B2), use this formula to auto-generate dates that stop at the last day of the month:
=IF(B1="", $A$1, IF(MONTH(B1+1)=MONTH($A$1), B1+1, ""))
- Drag this formula down the column. It will keep adding 1 day until the next date would jump to the next month, then stop with a blank cell.
- This automatically handles 31-day months, 30-day months, and even February (including leap years)—no manual adjustments required.
Step 3: Auto-Fill Corresponding Weekdays
In the adjacent cell (e.g., C2), use this formula to pull the weekday name for each date:
=IF(B2<>"", TEXT(B2, "dddd"), "")
- Drag this down alongside the date column. It will only show a weekday when there's a valid date in the cell next to it, keeping the template clean.
Bonus: Protect the Template from Accidental Edits
To prevent staff from messing up the auto-fill logic:
- Right-click the input cell (
A1) > Format Cells > Protection > Check "Locked". - Go to Review > Protect Sheet (you can set a simple password if needed).
This locks all formula cells, leaving only the input date field editable.
Why This Fixes the 31-Day Problem
The formula checks if the next date is still in the same month as your input first day. Unlike drag-fill (which can confuse less tech-savvy users), this dynamic logic automatically stops at the last day of the month—so January, March, May, July, August, October, and December will all fill to the 31st without extra effort.
内容的提问来源于stack exchange,提问作者Jfwhyte8

