Create an Excel Macro to Move Values in a Repeating Pattern
Question details
The user needs a VBA macro that shifts specific cell values following a repeating interval pattern (e.g., A2 to B1, A5 to B4, A8 to B7) while moving only one sequence per macro run.
- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Automating the relocation of specific data points from one column to another based on a fixed interval, processing one step at a time for better control.
- Observed behavior
- The user wants a script that tracks the number of times it has been executed, calculates the next target cell in the interval, moves its value one row up and one column right, and clears the original cell.
Ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm) before testing, and back up your original data since VBA actions generally cannot be reversed using the standard Undo command.
Use a Run-Tracking VBA Macro to Move Cells
This method uses a VBA script that tracks execution runs to calculate the next target cell (e.g., skipping every 3 rows), moving it up and right while clearing the source.
To achieve a step-by-step movement, the macro must remember its previous state. This can be done by defining a static variable within the VBA code or by storing a counter value in a hidden cell in your worksheet.
Navigate to the Developer tab and click on 'Visual Basic', or press ALT + F11 on your keyboard.
In the VBA Editor window, click 'Insert' from the top menu and select 'Module' to create a blank script canvas.
Write a subroutine with a Static variable (e.g., `Static RunCount As Integer`). Calculate the target row using a formula like `Row = 2 + (RunCount * 3)` to target rows 2, 5, 8, etc.
Add the command to move the data: `Cells(Row - 1, 2).Value = Cells(Row, 1).Value`, then clear the original data with `Cells(Row, 1).ClearContents`. Increment `RunCount` by 1 at the end of the script.
Close the VBA editor. On your worksheet, go to the Developer tab, click 'Insert', choose a Button (Form Control), draw it on the sheet, and assign your new macro to it.
Automate Repeating Data Patterns with WPS Spreadsheet
WPS Spreadsheet fully supports VBA macros, allowing you to run, edit, and create complex automation scripts. You can easily set up repeating pattern movements with a highly compatible, built-in VBA editor.
- 1. Open WPS Spreadsheet: Launch WPS Office and open your workbook in WPS Spreadsheet.
- 2. Access the Developer Tools: Click on the Developer tab in the ribbon and select 'VBA Editor' to open the coding environment.
- 3. Paste Your Script: Insert a new module from the top menu and paste your run-tracking macro code into the window.
- 4. Execute the Macro: Save your code and run the macro directly, or map it to a shortcut button on your sheet to process your pattern sequence one click at a time.

Frequently Asked Questions
Why doesn't the macro work after I close and reopen the file?
You may have saved the file as a standard Excel Workbook (.xlsx), which automatically strips out all macro code. Always ensure you 'Save As' a Macro-Enabled Workbook (.xlsm) or Binary Workbook (.xlsb).
Can I undo a macro after it moves my cell data?
No, standard undo (Ctrl+Z) does not work for actions performed by VBA macros. It is highly recommended to save a copy of your worksheet data before running an untested script.
How do I change the macro to move the cell two columns over instead of one?
You need to modify the target column index in your VBA code. For example, change `Cells(Row - 1, 2)` to `Cells(Row - 1, 3)` to output the data into column C instead of column B.
How do I enable the Developer tab to access the VBA editor?
In Excel or WPS Spreadsheet, go to Options (File > Options), select 'Customize Ribbon,' and check the box next to 'Developer' in the main tabs list on the right pane.




