Consolidate Rows from Multiple Excel Worksheets with VBA
Question details
Consolidate selected rows from many worksheets into specified columns on one worksheet using VBA.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A workbook may contain thousands of worksheets, and selected source rows need to be collected on a consolidation sheet.
- Observed behavior
- The user wants source values placed in the next available destination rows without copying each worksheet manually.
Create a destination worksheet named Consolidation and reserve columns D:M for the output. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm), and check that macros are permitted in your Excel environment.
Run a VBA macro to append selected rows from each worksheet
Use this macro to copy values from A4:J10 on every other worksheet into columns D:M of the Consolidation sheet.
The macro appends seven rows per source sheet, including blank rows, and skips the Consolidation sheet. It writes values directly rather than using the clipboard and temporarily turns off screen updating, events, and automatic calculation.
The next output row is determined by the last used cell in columns D:M, with row 2 as the minimum. Change the source range and destination dimensions together if you need a different selection.
In Excel, open the .xlsm workbook and select Developer > Visual Basic. If the Developer tab is hidden, enable it through Excel's ribbon customization settings.
In the VBA editor, select Insert > Module and paste this code: Sub ConsolidateRows() Dim ws As Worksheet, wsOutput As Worksheet Dim lastCell As Range Dim nextRow As Long Dim oldCalc As XlCalculation Dim oldScreen As Boolean, oldEvents As Boolean Dim errorMessage As String oldCalc = Application.Calculation oldScreen = Application.ScreenUpdating oldEvents = Application.EnableEvents On Error GoTo CleanUp Set wsOutput = ThisWorkbook.Worksheets("Consolidation") Application.ScreenUpdating = False Application.EnableEvents = False Application.Calculation = xlCalculationManual Set lastCell = wsOutput.Range("D:M").Find(What:="*", _ After:=wsOutput.Range("D1"), LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious, MatchCase:=False) nextRow = 2 If Not lastCell Is Nothing Then If lastCell.Row >= 2 Then nextRow = lastCell.Row + 1 End If For Each ws In ThisWorkbook.Worksheets If ws.Name <> wsOutput.Name Then If nextRow + 6 > wsOutput.Rows.Count Then Err.Raise vbObjectError + 1000, , "Not enough rows on the Consolidation sheet." End If wsOutput.Cells(nextRow, "D").Resize(7, 10).Value2 = ws.Range("A4:J10").Value2 nextRow = nextRow + 7 End If Next ws CleanUp: If Err.Number <> 0 Then errorMessage = Err.Description On Error Resume Next Application.Calculation = oldCalc Application.ScreenUpdating = oldScreen Application.EnableEvents = oldEvents On Error GoTo 0 If Len(errorMessage) > 0 Then MsgBox "Consolidation stopped: " & errorMessage, vbExclamation Else MsgBox "Consolidation complete." End If End Sub
Select Developer > Macros, choose ConsolidateRows, and click Run. Open the Consolidation sheet and check the values in columns D:M.

Consolidate worksheet rows in WPS Spreadsheets
Use the VBA macro in WPS Spreadsheets if your installation supports VBA macros. Availability and compatibility can vary by edition, so test the macro in your environment.
- 1. Open the workbook: Open the workbook in WPS Spreadsheets and create a worksheet named Consolidation.
- 2. Check VBA availability: Look for Developer > Visual Basic or the macro tools in your WPS Spreadsheets ribbon. If VBA support is unavailable, check the options for your WPS edition before continuing.
- 3. Add and run the macro: Open the VBA editor, select Insert > Module, and paste the ConsolidateRows macro above. Run it from the macro dialog.
- 4. Review and save: Check columns D:M on the Consolidation sheet, then use Save As to save the workbook in XLSM format.

Frequently Asked Questions
How do I copy a different source range?
In the VBA editor, change ws.Range("A4:J10") to the desired range. Also change Resize(7, 10) and the row increment and capacity check to match the new range's height and width.
Does the macro copy formulas and formatting?
No. The Value2 assignment writes the current values only. It does not copy formulas or formatting.
How can I exclude additional worksheets?
Edit the If condition inside the For Each loop to exclude their names, for example: If ws.Name <> wsOutput.Name And ws.Name <> "Summary" Then.
Why does the macro stop before processing every sheet?
Check the displayed error message. The Consolidation sheet may be missing or protected, or the output may exceed Excel's row limit. Any rows written before the error remain on the destination sheet.




