VBA & Macro Problems

How to Use an Excel VBA Macro to Fill Dates for the Current Week

Jason MillerJason Miller Nov 2, 2026 870 views

Question details

The user wants to use a VBA macro assigned to a button to automatically fill specific cells with the dates of the current week (Sunday through Saturday).

How to Use an Excel VBA Macro to Fill Dates for the Current Week
Product
Excel
Device & OS
not provided
Scenario
Automating weekly date entries in specific spreadsheet cells to avoid manual data entry each week.
Observed behavior
A macro script is needed to dynamically calculate the dates for Sunday through Saturday based on the system's current date and populate them into cells C2, E2, G2, I2, K2, M2, and O2.
Before you start

Ensure that the Developer tab is enabled in your Excel ribbon and that your workbook is saved as a Macro-Enabled Workbook (.xlsm) so the VBA code can execute properly.

Solution 1Recommended

Use DateAdd and Weekday Functions in VBA

Implement a VBA script that calculates the current week's dates dynamically and assign it to a clickable button for instant date population.

This method uses the VBA built-in functions DateAdd and Weekday to determine the current system date and calculate the corresponding dates for Sunday through Saturday of that week.

By assigning this code to a form control button, you can refresh the dates in your designated cells with a single click every time a new week begins.

1
Open the VBA Editor

Press 'Alt + F11' to open the Visual Basic for Applications (VBA) editor. Go to 'Insert' > 'Module' to create a new blank module.

2
Paste the Macro Code

Copy and paste the following code into the module window: Sub Button5_Click() Range("C2").Value = DateAdd("d", 0 - Weekday(Date, vbMonday), Date) Range("E2").Value = DateAdd("d", 1 - Weekday(Date, vbMonday), Date) Range("G2").Value = DateAdd("d", 2 - Weekday(Date, vbMonday), Date) Range("I2").Value = DateAdd("d", 3 - Weekday(Date, vbMonday), Date) Range("K2").Value = DateAdd("d", 4 - Weekday(Date, vbMonday), Date) Range("M2").Value = DateAdd("d", 5 - Weekday(Date, vbMonday), Date) Range("O2").Value = DateAdd("d", 6 - Weekday(Date, vbMonday), Date) End Sub

3
Insert a Form Button

Close the VBA editor. Go to the 'Developer' tab, click 'Insert', and select 'Button (Form Control)'. Draw the button on your worksheet.

4
Assign the Macro

Once the button is drawn, the 'Assign Macro' dialog will appear. Select 'Button5_Click' (or the name you gave your subroutine) and click 'OK'.

5
Run and Save

Click the newly created button to populate cells C2 through O2 with the current week's dates. Go to 'File' > 'Save As' and select 'Excel Macro-Enabled Workbook (*.xlsm)' to preserve the code.

Use DateAdd and Weekday Functions in VBA
Automation Complete: The dates will automatically update relative to whatever day you click the button, always finding the correct Sunday through Saturday for the current system week.
Automate with WPS Spreadsheet

Run Macros Seamlessly in WPS Spreadsheet

WPS Spreadsheet offers robust support for VBA and macros, allowing you to run your Excel scripts without missing a beat. Automate repetitive tasks like date-filling effortlessly within a clean, intuitive interface.

  1. 1. Enable the Developer Tab: Open WPS Spreadsheet, navigate to the 'Developer' tab, and ensure macro capabilities are active.
  2. 2. Access the VBA Editor: Click 'VBA Editor' to paste your custom date-calculation macro code into a new module.
  3. 3. Assign and Run: Insert a button, assign your macro, and click to instantly populate the current week's dates in your active sheet.
Full support for VBA macros and advanced scripting capabilities.Highly compatible with Microsoft Excel (.xlsm) and (.xls) macro formats.Lightweight program offering fast processing for automated tasks.
microsoft office alternative - wps office

Frequently Asked Questions

How do I change the starting day of the week in the macro?

You can modify the 'vbMonday' constant in the Weekday function to 'vbSunday' or another day parameter. This will shift the baseline used for calculating the offset of the current week's dates.

Why am I getting a security warning when opening the file?

By default, macro execution is disabled for security reasons to prevent malicious code from running. You must click 'Enable Content' in the yellow warning bar at the top of the screen or adjust your Trust Center settings to allow the macro to run.

Can I place the dates in different rows or columns?

Yes. Simply update the cell references in the VBA code. For example, change Range("C2") to Range("A1") to output the first date into cell A1 instead.

What happens if I click the macro button next week?

Because the macro references the system's current date using the 'Date' function, clicking it next week will automatically overwrite the existing cells with the new dates corresponding to that specific week.