Consolidate data from multiple sheets except one worksheet

strongman86

Board Regular
Joined
Feb 15, 2017
Messages
115
Office Version
  1. 2019
Platform
  1. Windows
Hi guys,

I got this code working, but I need to add another worksheet which code would ignore (sheet called "Data"). Can you please fix code:

VBA Code:
Sub Consolidate()

    Dim arr()   As Variant
    Dim ws      As Worksheet
    Dim wMast   As Worksheet
    Dim x       As Long
    Dim y       As Long
        
    Set wMast = Sheets("master")
    
    Application.ScreenUpdating = False
    
    For Each ws In ActiveWorkbook.Worksheets
        With ws
            If .Name <> wMast.Name Then
                x = .Cells(.Rows.Count, 25).End(xlUp).Row
                y = .Cells(x, .Columns.Count).End(xlToLeft).Column
                arr = .Cells(x, 1).Resize(, y).Value
                wMast.Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(, UBound(arr, 2)).Value = arr
                Erase arr
            End If
        End With
    Next ws
    
    Application.ScreenUpdating = True
    
    Set wMast = Nothing
    
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
untested, but try modifying a single line:

If .Name <> wMast.Name and .Name <> "Data" Then
 
Upvote 0
Hi,
try this update to your code & see id does what you want

VBA Code:
Sub Consolidate()

    Dim arr()   As Variant, IgnoreSheet As Variant
    Dim ws      As Worksheet, wMast  As Worksheet
    Dim x       As Long, y      As Long
    
    Set wMast = ThisWorkbook.Worksheets("master")
 
    IgnoreSheet = Array(wMast.Name, "Data")
 
    Application.ScreenUpdating = False
 
    For Each ws In ActiveWorkbook.Worksheets
        With ws
            If IsError(Application.Match(.Name, IgnoreSheet, 0)) Then
                x = .Cells(.Rows.Count, 25).End(xlUp).Row
                y = .Cells(x, .Columns.Count).End(xlToLeft).Column
                arr = .Cells(x, 1).Resize(, y).Value
                wMast.Cells(wMast.Rows.Count, 1).End(xlUp).Offset(1).Resize(, UBound(arr, 2)).Value = arr
                Erase arr
            End If
        End With
    Next ws
 
    Application.ScreenUpdating = True
 
    Set wMast = Nothing
 
End Sub

You can add to the Ignore array as required

Dave
 
Upvote 0
Hi,
try this update to your code & see id does what you want

VBA Code:
Sub Consolidate()

    Dim arr()   As Variant, IgnoreSheet As Variant
    Dim ws      As Worksheet, wMast  As Worksheet
    Dim x       As Long, y      As Long
   
    Set wMast = ThisWorkbook.Worksheets("master")
 
    IgnoreSheet = Array(wMast.Name, "Data")
 
    Application.ScreenUpdating = False
 
    For Each ws In ActiveWorkbook.Worksheets
        With ws
            If IsError(Application.Match(.Name, IgnoreSheet, 0)) Then
                x = .Cells(.Rows.Count, 25).End(xlUp).Row
                y = .Cells(x, .Columns.Count).End(xlToLeft).Column
                arr = .Cells(x, 1).Resize(, y).Value
                wMast.Cells(wMast.Rows.Count, 1).End(xlUp).Offset(1).Resize(, UBound(arr, 2)).Value = arr
                Erase arr
            End If
        End With
    Next ws
 
    Application.ScreenUpdating = True
 
    Set wMast = Nothing
 
End Sub

You can add to the Ignore array as required

Dave
Works perfectly. Thanks Dave.
 
Upvote 0
welcome glad we were able to help & appreciate feedback

Dave
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,595
Members
449,089
Latest member
Motoracer88

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