Use Excel VBA to Combine Data from Visible Worksheets
Question details
Combine data from visible Excel worksheets into a YEARLY REPORT sheet while skipping hidden sheets.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A workbook contains multiple source worksheets whose data should be appended to a single report using VBA.
- Observed behavior
- The report should contain one header followed by data from visible source sheets, without including hidden sheets or the report sheet itself.
Create a worksheet named YEARLY REPORT and ensure each source sheet has the same column layout, with headers in row 1. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm), and enable macros only if you trust the code and workbook.
Append visible worksheet data with a qualified VBA macro
Use this macro when source sheets share a header layout and data starts in row 2.
The macro uses explicit worksheet references and finds the last used row and column instead of relying on End(xlDown) or End(xlToRight). It copies values, not formatting or formulas.
If YEARLY REPORT already contains data, new rows are appended without adding another header. Running the macro again appends the source data again.
In the desktop version of Excel, open the workbook and choose Developer > Visual Basic, then select Insert > Module.
Paste this code into the module: Sub CombineVisibleSheets() Dim wb As Workbook Dim ws As Worksheet Dim report As Worksheet Dim lastCell As Range Dim lastRow As Long Dim lastCol As Long Dim nextRow As Long Set wb = ThisWorkbook Set report = wb.Worksheets("YEARLY REPORT") For Each ws In wb.Worksheets If ws.Visible = xlSheetVisible And ws.Name <> report.Name Then Set lastCell = ws.Cells.Find(What:="*", After:=ws.Cells(1, 1), LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False, SearchFormat:=False) If Not lastCell Is Nothing Then lastRow = lastCell.Row If lastRow > 1 Then Set lastCell = ws.Cells.Find(What:="*", After:=ws.Cells(1, 1), LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False, SearchFormat:=False) lastCol = lastCell.Column Set lastCell = report.Cells.Find(What:="*", After:=report.Cells(1, 1), LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False, SearchFormat:=False) If lastCell Is Nothing Then report.Cells(1, 1).Resize(1, lastCol).Value = ws.Cells(1, 1).Resize(1, lastCol).Value nextRow = 2 Else nextRow = lastCell.Row + 1 End If report.Cells(nextRow, 1).Resize(lastRow - 1, lastCol).Value = ws.Cells(2, 1).Resize(lastRow - 1, lastCol).Value End If End If End If Next ws End Sub
In Excel, choose Developer > Macros, select CombineVisibleSheets, and click Run. Open YEARLY REPORT and check the header and appended rows.

Work with Excel reports in WPS Spreadsheets
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for Excel formats, making it easy to move everyday report work between office suites. It does not directly fix Excel VBA issues; macro support and compatibility can vary by WPS version.

Frequently Asked Questions
Does the macro include hidden worksheets?
No. The condition ws.Visible = xlSheetVisible includes only visible worksheets and also excludes YEARLY REPORT.
What happens if a source sheet is empty or has only a header?
The macro skips it. A source sheet must have content below row 1 for its rows to be appended.
Will the macro copy formulas and formatting?
No. The assignment uses Value, so it copies displayed values rather than formulas or formatting.
Why does the report contain duplicate rows after I run the macro twice?
The macro appends data each time it runs and does not track previous imports. Review or clear existing report contents before rerunning it if you need a fresh report.




