VBA & Macro Problems

Use Excel VBA to Copy Multiple Ranges Based on a Cell Value

Anum MushtaqAnum Mushtaq Dec 2, 2026 868 views

Question details

Automatically copy two source ranges to separate destination ranges based on a control cell value.

Use Excel VBA to Copy Multiple Ranges Based on a Cell Value
Product
Microsoft Excel
Device & OS
not provided
Scenario
A control cell selects the destination columns for two source columns, avoiding a separate macro for each day.
Observed behavior
When the control cell changes, the corresponding source values should be copied to the mapped destination columns.
Before you start

Identify the control cell, source ranges, and destination ranges for each control value. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) and enable macros if your security settings permit them.

Solution 1Recommended

Use a Worksheet_Change event to map values to destination ranges

Use one worksheet event and a Select Case block to choose where both source ranges are copied.

The example uses AH69 as the control cell and copies values from AG71:AG84 and AH71:AH84. Control values 1 and 2 are illustrative; replace or extend the cases and destination ranges to match your schedule. The destination ranges must have the same dimensions as their source ranges.

1
Open the worksheet code module

In Excel, right-click the worksheet tab that contains AH69 and select View Code. Paste the event procedure into that worksheet's code module, rather than a standard module.

2
Add the change event

Paste this code: Private Sub Worksheet_Change(ByVal Target As Range) If Intersect(Target, Me.Range("AH69")) Is Nothing Then Exit Sub On Error GoTo ErrorHandler Application.EnableEvents = False Select Case Me.Range("AH69").Value Case 1 Me.Range("C71:C84").Value = Me.Range("AG71:AG84").Value Me.Range("E71:E84").Value = Me.Range("AH71:AH84").Value Case 2 Me.Range("D71:D84").Value = Me.Range("AG71:AG84").Value Me.Range("F71:F84").Value = Me.Range("AH71:AH84").Value End Select CleanUp: Application.EnableEvents = True Exit Sub ErrorHandler: MsgBox "The ranges could not be copied: " & Err.Description Resume CleanUp End Sub

3
Customize and test the mappings

Add or edit Case entries in the code for each control value and its two destination ranges. Return to the worksheet, enter a mapped value such as 1 in AH69, and check the corresponding destination columns.

Use a Worksheet_Change event to map values to destination ranges
Values only: The assignments copy cell values, not formulas or formatting. Unmapped control values do nothing, and the event does not run when AH69 changes solely because a formula recalculates.
Free Microsoft Office alternative

Work with spreadsheet ranges in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface. It opens common Excel formats, making it easy to move spreadsheet work between applications; however, Excel VBA event macros may not run in every WPS installation.

Work with source and destination cell ranges in WPS SpreadsheetsCompatible with common Microsoft Excel formats, including XLSXFamiliar interface for a smoother transition from ExcelFree tools for everyday spreadsheet editing
microsoft office alternative - wps office

Frequently Asked Questions

Where should I put the Worksheet_Change code?

Right-click the worksheet tab containing the control cell, select View Code, and paste the procedure into that worksheet's code module.

How do I add a destination for another day?

Add another Case entry inside Select Case Me.Range("AH69").Value, then assign both source ranges to the two destination ranges for that value.

Will the macro copy formulas and formatting?

No. Assignments using Range.Value copy values only. Use an appropriate Copy and PasteSpecial operation if you need formulas or formatting instead.

Why does nothing happen when AH69 changes through a formula?

Worksheet_Change does not fire for changes caused only by recalculation. A formula-driven control cell requires a different approach, such as monitoring its value in a Worksheet_Calculate event.

What if the event does not run after an error?

Open the VBA editor and check whether Application.EnableEvents is False. In the Immediate window, enter Application.EnableEvents = True. Also confirm that macros are enabled and the code is in the correct worksheet module.