VBA & Macro Problems

Excel VBA: Consolidate Visible Worksheets into a Summary Sheet

Bushra ParveenBushra Parveen Nov 22, 2026 870 views

Question details

Create a summary sheet that combines data from visible worksheets and can be refreshed as new sheets are added.

Consolidate Visible Excel Worksheets into a Summary Sheet with VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
A workbook receives a new worksheet each month, and its data from row 10 onward needs to be included in a consolidated summary.
Observed behavior
The desired summary contains data from columns A through the last used column up to Q on each visible source worksheet.
Before you start

Open the workbook in desktop Excel and save it as an Excel Macro-Enabled Workbook (.xlsm). The macro clears existing contents on a sheet named Summary-Sheet, so check that sheet before running it.

Solution 1Recommended

Run a VBA macro to rebuild the summary from visible worksheets

Use this macro to create or refresh a values-only summary whenever source sheets change.

The macro searches columns A through Q from row 10 downward on each visible worksheet. It excludes Summary-Sheet and hidden sheets, then appends each source range to the summary.

The output starts at A1 and contains values, not formulas, formatting, source sheet names, or links. Run the macro again after adding or updating a worksheet.

1
Open the VBA editor

In desktop Excel, open the workbook and choose Developer > Visual Basic, or press Alt+F11 on Windows.

2
Insert a module

In the VBA editor, select the workbook in Project Explorer and choose Insert > Module.

3
Paste the macro

Paste this code into the module: Sub ConsolidateVisibleSheets() Dim ws As Worksheet, summary As Worksheet Dim lastRowCell As Range, lastColCell As Range, sourceRange As Range Dim lastRow As Long, lastCol As Long, nextRow As Long Dim oldCalc As XlCalculation Dim oldScreen As Boolean, oldAlerts As Boolean Dim errorMessage As String oldCalc = Application.Calculation oldScreen = Application.ScreenUpdating oldAlerts = Application.DisplayAlerts On Error GoTo HandleError Application.ScreenUpdating = False Application.DisplayAlerts = False Application.Calculation = xlCalculationManual On Error Resume Next Set summary = ThisWorkbook.Worksheets("Summary-Sheet") On Error GoTo HandleError If summary Is Nothing Then Set summary = ThisWorkbook.Worksheets.Add(After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)) summary.Name = "Summary-Sheet" Else summary.Cells.ClearContents End If nextRow = 1 For Each ws In ThisWorkbook.Worksheets If ws.Name <> summary.Name And ws.Visible = xlSheetVisible Then Set lastRowCell = ws.Range("A10:Q" & ws.Rows.Count).Find(What:="*", LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False, SearchFormat:=False) If Not lastRowCell Is Nothing Then lastRow = lastRowCell.Row Set lastColCell = ws.Range("A10:Q" & lastRow).Find(What:="*", LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False, SearchFormat:=False) lastCol = lastColCell.Column Set sourceRange = ws.Range(ws.Cells(10, 1), ws.Cells(lastRow, lastCol)) summary.Cells(nextRow, 1).Resize(sourceRange.Rows.Count, sourceRange.Columns.Count).Value2 = sourceRange.Value2 nextRow = nextRow + sourceRange.Rows.Count End If End If Next ws GoTo CleanUp HandleError: errorMessage = Err.Description CleanUp: Application.Calculation = oldCalc Application.ScreenUpdating = oldScreen Application.DisplayAlerts = oldAlerts If Len(errorMessage) > 0 Then MsgBox "Consolidation stopped: " & errorMessage, vbExclamation Else MsgBox "Summary updated.", vbInformation End If End Sub

4
Run and refresh

Return to Excel, choose Developer > Macros, select ConsolidateVisibleSheets, and click Run. Repeat after a new sheet has been populated.

Run a VBA macro to rebuild the summary from visible worksheets
Workbook and calculation scope: ThisWorkbook means the workbook containing the macro. The macro temporarily switches calculation to manual and restores the previous Excel settings afterward; calculate the workbook first if source formulas need updating.
Free Microsoft Office alternative

Review and edit Excel summaries in WPS Spreadsheets

WPS Office is a free, lightweight alternative for opening and editing spreadsheet workbooks in a familiar interface. Its Excel format compatibility helps you move existing files between applications, though it does not fix Excel VBA issues.

Review consolidated worksheet data in WPS SpreadsheetsOpen and edit Microsoft Excel XLSX filesUse a familiar spreadsheet interface for a smoother transitionWork with a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Will a newly added worksheet appear in the summary automatically?

No. After adding and populating the worksheet, choose Developer > Macros and run ConsolidateVisibleSheets again.

Are hidden template sheets included?

No. The macro checks for xlSheetVisible, so hidden and very hidden sheets are skipped. Unhide a sheet before running the macro if it should be included.

Does the macro copy formulas or formatting?

No. It writes the source cells' current values using Value2. It does not copy formulas, formatting, or links to the source sheets.

What happens to existing data on Summary-Sheet?

The macro clears the sheet's existing cell contents before rebuilding the summary. Check the sheet before selecting Developer > Macros > Run.

Why is data beyond column Q missing?

The macro searches only columns A through Q, starting at row 10. Change the Q references in the Find ranges if the source data extends farther.