Combine all sheets into one - need help with existing code

rachel06

Board Regular
Joined
Feb 3, 2016
Messages
126
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a spreadsheet with multiple sheets that I need to combine into one. These sheets have reports with the exact same structure, using columns A-L and no headers. I want to copy the data into a sheet called "ALL" which does have headers, so it would need to start in row two.

Anyway, this is what I came up with but it made Excel not responsive. I'm sure there's a better way and I'd love some suggestions!

Code:
Option Explicit


Sub JobID()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    For Each ws In Worksheets
        If ws.Name <> "DASHBOARD" And ws.Name <> "ALL" Then
            With ws
            Range("A1:L1").Select
            Range(Selection, Selection.End(x1Down)).Select
            Selection.Copy
            Sheets("ALL").Select
            Cells(Rows.Count, "A").End(x1Up).Offset(1).Select
            End With
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try:
VBA Code:
Sub JobID()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    For Each ws In Worksheets
        If ws.Name <> "DASHBOARD" And ws.Name <> "ALL" Then
            With ws
                .UsedRange.Copy Sheets("ALL").Cells(Sheets("ALL").Rows.Count, "A").End(x1Up).Offset(1)
            End With
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Perhaps something like this.
VBA Code:
Sub JobID()
    Application.ScreenUpdating = False
    Dim WS As Worksheet
    Dim wsAll As Worksheet
    Dim LastRow As Long
    Dim rngSrc As Range
    Dim rngDest As Range
    
    Set wsAll = ThisWorkbook.Worksheets("ALL")
    
    For Each WS In Worksheets
        Select Case WS.Name
            Case "DASHBOARD", "ALL"
            Case Else
                With WS
                    Set rngSrc = .Range("A1:L" & .Range("A" & .Rows.Count).End(xlUp).Row)
                End With
                rngSrc.Copy
                
                With wsAll
                    LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
                    Set rngDest = .Cells(LastRow + 1, 1)
                    rngSrc.Copy
                    rngDest.PasteSpecial xlPasteValues
                End With
        End Select
    Next WS
    Application.ScreenUpdating = True
End Sub
 
Upvote 1
Solution
Try:
VBA Code:
Sub JobID()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    For Each ws In Worksheets
        If ws.Name <> "DASHBOARD" And ws.Name <> "ALL" Then
            With ws
                .UsedRange.Copy Sheets("ALL").Cells(Sheets("ALL").Rows.Count, "A").End(x1Up).Offset(1)
            End With
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub
Appreciate the quick response!! Getting an error "Compile error: Variable not defined" This part is highlighted from this line of code ".End(x1Up)"

Code:
.UsedRange.Copy Sheets("ALL").Cells(Sheets("ALL").Rows.Count, "A").End(x1Up).Offset(1)

Any suggestions? I have it set as Option Explicit.
 
Upvote 0
Could you upload a copy of your file (de-sensitized if necessary) to a free file sharing site like Dropbox.com and post a link to your file?
 
Upvote 0
Could you upload a copy of your file (de-sensitized if necessary) to a free file sharing site like Dropbox.com and post a link to your file?
Another user posted something that worked perfectly. Thanks so much for responding though - much appreciated!
 
Upvote 0
Perhaps something like this.
VBA Code:
Sub JobID()
    Application.ScreenUpdating = False
    Dim WS As Worksheet
    Dim wsAll As Worksheet
    Dim LastRow As Long
    Dim rngSrc As Range
    Dim rngDest As Range
   
    Set wsAll = ThisWorkbook.Worksheets("ALL")
   
    For Each WS In Worksheets
        Select Case WS.Name
            Case "DASHBOARD", "ALL"
            Case Else
                With WS
                    Set rngSrc = .Range("A1:L" & .Range("A" & .Rows.Count).End(xlUp).Row)
                End With
                rngSrc.Copy
               
                With wsAll
                    LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
                    Set rngDest = .Cells(LastRow + 1, 1)
                    rngSrc.Copy
                    rngDest.PasteSpecial xlPasteValues
                End With
        End Select
    Next WS
    Application.ScreenUpdating = True
End Sub
Perfect. Thank you!!!!
 
Upvote 0
Appreciate the quick response!! Getting an error "Compile error: Variable not defined" This part is highlighted from this line of code ".End(x1Up)"

Just to answer your question, the error likely to result if member inadvertently entering the number 1 when it should be l (lower case L)

Rich (BB code):
.End(xlUp)

Dave
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

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