Skip Empty Worksheets When Copying Data with Excel VBA
Question details
The user wants an Excel VBA macro to skip source worksheets without data and copy populated rows to the correct destination.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A macro combines data from multiple worksheets into a destination sheet while skipping headers and empty sources.
- Observed behavior
- Empty source sheets can cause the destination position to move unexpectedly, and a suggested macro ran without copying data from a populated sheet.
Identify a column that is populated through the last data row on every source sheet, and confirm the destination sheet name and header row. The example uses column J, row 1 for headers, and a destination sheet named Summary.
Check the last data row before copying each worksheet
Use this approach when each source sheet has headers in row 1 and column J reliably identifies its last data row.
The macro checks column J on each source sheet first. It calculates the next destination row only when the source has data below the header, then copies columns A through J.
Adjust the sheet name, checked column, and copied range to match your workbook. Column J must also identify the last copied row on the destination sheet.
In Excel, open the workbook and select Developer > Visual Basic. In the VBA editor, select Insert > Module.
Paste this code into the module: Sub CopyNonEmptySheets() Dim src As Worksheet Dim dest As Worksheet Dim lastRow As Long Dim nextRow As Long Set dest = ThisWorkbook.Worksheets("Summary") For Each src In ThisWorkbook.Worksheets If src.Name <> dest.Name Then lastRow = src.Cells(src.Rows.Count, "J").End(xlUp).Row If lastRow > 1 Then nextRow = dest.Cells(dest.Rows.Count, "J").End(xlUp).Row + 1 src.Range("A2:J" & lastRow).Copy Destination:=dest.Cells(nextRow, "A") End If End If Next src End Sub
In the code, replace Summary with your destination sheet name. If necessary, change both J column checks and the A2:J copy range to match the reliable data column and source range.
Return to Excel, select Developer > Macros, choose CopyNonEmptySheets, and select Run. Check that populated source rows appear on Summary and empty sheets add no rows.

Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface for opening and editing spreadsheets. Its format compatibility helps you move existing files between office suites; it does not fix a macro running in Microsoft Excel.

Frequently Asked Questions
Why does the macro run without copying a populated worksheet?
Check the column used in the last-row test. If column J has no data below row 1, the example skips that sheet even if other columns contain data. Change both J checks to a reliable column and adjust the copy range if needed.
How does the macro find the next destination row?
After finding a source with data, it uses dest.Cells(dest.Rows.Count, "J").End(xlUp).Row + 1 to find the row after the last populated cell in destination column J.
Does the macro copy the header from every sheet?
No. The example copies from row 2 through the last data row, so it assumes row 1 contains headers and that the Summary sheet already has its header.
What if my worksheets contain formulas that return blank strings?
The End(xlUp) check can treat those formula cells as used. Review the checked column and use a different test if formulas returning empty strings should not count as data.
How do I keep the macro in the workbook?
In Excel, select File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm). Run macros only from workbooks you trust.




