Consolidating Multiple Sheets into One - With one Exception!

robman63

New Member
Joined
Nov 6, 2017
Messages
4
Hello!

I have a Macro (listed below) which works PERFECTLY!

It takes multiple worksheets and joins all the data found across all the multiple sheets into 1 Worksheet called "Combined".

Unfortunately, I have 1 hidden worksheet called "lists" that I would prefer to keep out of the macro but it takes the information from there and uses it too. I do not want this.

-------------------

My question is: Is there a Statement or Expression I can add to this macro to prevent it from joining that particular sheet called lists?


Sub Combine()
Dim J As Integer
On Error Resume Next
Sheets(1).Select
Worksheets.Add
Sheets(1).Name = "Combined"
Sheets(2).Activate
Range("A1").EntireRow.Select
Selection.Copy Destination:=Sheets(1).Range("A1")
For J = 2 To Sheets.Count
Sheets(J).Activate
Range("A1").Select
Selection.CurrentRegion.Select
Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
Selection.Copy Destination:=Sheets(1).Range("A1000000").End(xlUp)(2)
Next
End Sub


Any help in this matter would be greatly appreciated! This is my first question on here! :O)
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
HI, and welcome to the board.
Try this
Code:
Sub Combine()
    Dim J As Integer
    On Error Resume Next
    Sheets(1).Select
    Worksheets.Add
    Sheets(1).Name = "Combined"
    Sheets(2).Activate
    Range("A1").EntireRow.Select
    Selection.Copy Destination:=Sheets(1).Range("A1")
    For J = 2 To Sheets.Count
        If Not Sheets(J).Name = "lists" Then
            Sheets(J).Activate
            Range("A1").Select
            Selection.CurrentRegion.Select
            Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
            Selection.Copy Destination:=Sheets(1).Range("A1000000").End(xlUp)(2)
        End If
    Next
End Sub
 
Upvote 0
Hi Fluff! Thank you for the quick response! Your mod on the macro worked, but it also threw it out of whack. it is skipping part of what the original macro did. I'm not sure why.

HI, and welcome to the board.
Try this
Code:
Sub Combine()
    Dim J As Integer
    On Error Resume Next
    Sheets(1).Select
    Worksheets.Add
    Sheets(1).Name = "Combined"
    Sheets(2).Activate
    Range("A1").EntireRow.Select
    Selection.Copy Destination:=Sheets(1).Range("A1")
    For J = 2 To Sheets.Count
        If Not Sheets(J).Name = "lists" Then
            Sheets(J).Activate
            Range("A1").Select
            Selection.CurrentRegion.Select
            Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
            Selection.Copy Destination:=Sheets(1).Range("A1000000").End(xlUp)(2)
        End If
    Next
End Sub
 
Upvote 0
What is it skipping?
All I did was add the if Statement.
That said, I would recommend removing this line
Code:
On Error Resume Next
As it simply masks any errors that may be occurring.
 
Upvote 0
What is it skipping?
All I did was add the if Statement.
That said, I would recommend removing this line
Code:
On Error Resume Next
As it simply masks any errors that may be occurring.

Hi Fluff!

Sorry about that! It was my mistake. It is working perfectly!

The problem is that my "combine" macro is part of a larger macro which calls 6 macros, "combine" being one of them and I overlooked a step. But your fix did it! Thank you!
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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