VBA consolidate sheets.

jakobt

Active Member
Joined
May 31, 2010
Messages
337
Have 15 sheet in same workbook.
Want to consolidate entries in column A to C in each sheet into a consolidated sheet called "Consolidated sheet"

Can this be done with a VBA formula?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
This is one way to do it.

Code:
Option Explicit

Sub ConsolidateSheets()
    Const sTargetWorksheetName As String = "Consolidated Sheet"
    Dim lCSWriteRow As Long
    Dim wks As Worksheet
    Dim lCSInitialIndex As Long
    
    'Clear the target worksheet
    Worksheets(sTargetWorksheetName).UsedRange.EntireRow.Delete
    
    'Processing it first would cause a blank row, so
    '  save its position and move it to end
    lCSInitialIndex = Sheets(sTargetWorksheetName).Index
    Sheets(sTargetWorksheetName).Move After:=Sheets(Sheets.Count)
    
    lCSWriteRow = 1
    For Each wks In ThisWorkbook.Worksheets
        Select Case wks.Name
        Case sTargetWorksheetName
            'Do nothing
        Case Else
            With wks
                Intersect(.UsedRange, .Range("A:C")).Copy _
                    Destination:=Worksheets(sTargetWorksheetName).Cells(lCSWriteRow, 1)
            End With
        End Select
        With Worksheets(sTargetWorksheetName)
            lCSWriteRow = .UsedRange.Row + .UsedRange.Rows.Count
        End With
    Next
    
    'Restore Consolidated Sheet position
    If lCSInitialIndex <> Sheets(sTargetWorksheetName).Index Then
        Sheets(sTargetWorksheetName).Move Before:=Sheets(lCSInitialIndex)
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,129
Messages
6,123,218
Members
449,091
Latest member
jeremy_bp001

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top