VBA & Macro Problems

Copy Excel VBA Rows Below a Destination Sheet Header

Olivia MillerOlivia Miller Nov 25, 2026 869 views

Question details

Copy matching rows to a destination worksheet starting at a fixed row below a reserved area.

Copy Excel VBA Rows Below a Destination Sheet Header
Product
Microsoft Excel
Device & OS
not provided
Scenario
A VBA macro needs to refresh matching records on a destination sheet without overwriting titles, analysis, or column headers above the output.
Observed behavior
Matching records should start at the chosen output row, with the reserved area above it left unchanged.
Before you start

Identify the first output row, the source and destination sheet names, and the columns that the macro may overwrite. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) if it is not already in a macro-enabled format.

Solution 1Recommended

Set a Fixed Starting Row and Clear Only the Output Range

Use this approach when rows above the output are reserved for titles, analysis, and headers.

The example assumes source data is in columns A:E, column A contains the matching value, and destination headers are on row 10. It clears A11:E10000 before copying; change the sheet names, match value, and ranges to fit your workbook.

1
Open the VBA editor

In Excel, open Developer > Visual Basic, then select Insert > Module.

2
Add the copy macro

Paste the following code into the module: Sub CopyMatchingRows() Dim sourceSheet As Worksheet, destinationSheet As Worksheet Dim lastRow As Long, sourceRow As Long, destinationRow As Long Set sourceSheet = ThisWorkbook.Worksheets("Source") Set destinationSheet = ThisWorkbook.Worksheets("Destination") lastRow = sourceSheet.Cells(sourceSheet.Rows.Count, "A").End(xlUp).Row destinationRow = 11 destinationSheet.Range("A11:E10000").ClearContents For sourceRow = 2 To lastRow If sourceSheet.Cells(sourceRow, "A").Value = "Approved" Then If destinationRow > 10000 Then MsgBox "The destination output range is full." Exit Sub End If sourceSheet.Range("A" & sourceRow & ":E" & sourceRow).Copy _ Destination:=destinationSheet.Range("A" & destinationRow) destinationRow = destinationRow + 1 End If Next sourceRow End Sub

3
Adjust the output and condition

In the code, replace Source, Destination, and Approved with your sheet names and matching value. If you change the first output row or last output row, update destinationRow, the cleared range, and the capacity check together.

4
Run the macro

Return to Excel, select Developer > Macros, choose CopyMatchingRows, and click Run. Check that matching rows begin at row 11 and that the reserved rows above remain unchanged.

Set a Fixed Starting Row and Clear Only the Output Range
Keep the output range dedicated: ClearContents removes values and formulas in A11:E10000 but leaves formatting in place. The copy operation can also overwrite formatting in destination cells. Do not include unrelated data in the output range; enlarge it if more than 9,990 matching rows are needed.
Free Microsoft Office alternative

Work With Excel Spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for Excel formats, making it easy to move everyday spreadsheet work. VBA support can vary by edition and setup, so verify macro compatibility before relying on this Excel macro.

Use a familiar spreadsheet interface to work with headers and reserved rows.Open and edit Microsoft Excel XLSX files.Move everyday spreadsheet work to a lightweight Office alternative.Use WPS Office free for common spreadsheet tasks.
microsoft office alternative - wps office

Frequently Asked Questions

How do I start copying at a different row?

Change destinationRow = 11 to your first output row. Also change the start of the ClearContents range so it begins at the same row and does not include your headers.

Will ClearContents remove my destination headers?

Not if the cleared range starts below them. For example, Range("A11:E10000").ClearContents leaves headers in row 10 untouched, but removes values and formulas within the specified range.

How do I change which rows are copied?

Edit the If condition in the VBA editor. For example, replace "Approved" with the value you want to match in source column A, or change the column reference to match another column.

Why does the macro stop when the destination range is full?

The example limits output to row 10000 to avoid writing outside the cleared area. If you need more space, enlarge the ClearContents range and update the destinationRow capacity check to the same last row.