How to Copy an Excel Formula Column Multiple Times Using a VBA Macro
Question details
The user needs a VBA macro to dynamically duplicate a formula column into a specific number of new adjacent columns based on a variable numeric count.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Automating the duplication of formula columns depending on variable data inputs (e.g., employee count marked 'Y') to scale spreadsheet calculations without manual copying.
- Observed behavior
- The formula column must automatically expand into the exact number of adjacent columns required (such as columns C, D, and E if the count is 3), while ensuring all relative cell references adjust correctly.
Ensure your file is saved as a Macro-Enabled Workbook (.xlsm) and that you have enabled Developer tools and macros in your spreadsheet security settings.
Use a VBA Macro to Dynamically Copy the Formula Column
Execute a custom VBA script that reads the desired column count from a designated cell and duplicates the formula column accordingly.
This macro utilizes the Range.Copy method, which replicates standard copy-pasting behavior in Excel. By defining the source range and dynamically resizing the destination range based on your target count, the formulas will duplicate perfectly while keeping all relative references intact.
Press Alt + F11 on your keyboard to launch the Microsoft Visual Basic for Applications (VBA) editor.
Click on 'Insert' in the top menu bar and select 'Module' to create a blank script window.
Copy the macro script provided below and paste it into the module window. This specific script reads the target count from cell B6 and copies the formulas starting from C9 across the required number of columns. Sub CopyColumns() Dim YCount As Long Dim FormulaRange As Range Dim DestinationRange As Range With ActiveSheet YCount = .Range("B6").Value Set FormulaRange = .Range(.Cells(9, "C"), .Cells(.Rows.Count, "C").End(xlUp)) Set DestinationRange = .Range("C9").Resize(FormulaRange.Rows.Count, YCount) FormulaRange.Copy DestinationRange End With End Sub
Close the VBA editor and return to your worksheet. Press Alt + F8, select 'CopyColumns' from the Macro dialog box, and click 'Run' to execute the automation.

Run VBA Macros Seamlessly in WPS Spreadsheet
WPS Spreadsheet fully supports VBA macros in its advanced versions, allowing you to execute scripts to automatically copy formulas and manage complex data. It offers a familiar interface that makes automating spreadsheet tasks straightforward.
- 1. Open Your Workbook: Launch WPS Spreadsheet and open your macro-enabled workbook (.xlsm).
- 2. Access Developer Tools: Navigate to the 'Tools' tab on the ribbon and click on 'Developer' to access macro features.
- 3. Edit the VBA Script: Click 'Visual Basic Editor' to open the environment where you can paste and modify your formula-copying VBA script.
- 4. Execute the Macro: Run your macro directly from the Macros menu to automatically duplicate your formula columns.

Frequently Asked Questions
How do I change the cell that determines the number of columns to copy?
In the provided VBA script, locate the line `YCount = .Range("B6").Value`. Change 'B6' to the exact cell reference that contains your target numeric count.
Why does the macro overwrite existing data in adjacent columns?
The `Range.Copy DestinationRange` command automatically pastes data into the specified spatial area. You must ensure the columns to the right of your source column are empty before running the macro, or modify the script to insert new blank columns first.
Does copying formulas via VBA preserve relative references?
Yes, using the `FormulaRange.Copy` method behaves identically to manual copy-pasting. Relative references will adjust automatically for each new column, while absolute references (e.g., $A$1) will remain firmly locked.
Can I assign this VBA macro to a clickable button?
Yes. Go to the Developer tab, insert a Button (Form Control), draw it onto your worksheet, and when the configuration prompt appears, assign the 'CopyColumns' macro to it. This allows you to run the automation with a single click.




