+ Reply to Thread
Results 1 to 2 of 2

Consolidating Multiple Tabs of Data

Hybrid View

  1. #1
    Registered User
    Join Date
    05-16-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    8

    Consolidating Multiple Tabs of Data

    Hi,

    I have multiple tabs with identical 1st row column labels. Each has varying number of rows. How can I combine each tab into one master worksheet?

    I want each subsequent tab brought in immediately following the preceeding tab's final row. The consolidate feature in Excel isn't allowing me to do this, but rather wants to aggregate a given row from each tab into one row.

  2. #2
    Valued Forum Contributor
    Join Date
    11-20-2012
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2010
    Posts
    597

    Re: Consolidating Multiple Tabs of Data

    there you go, hope it works the way you want, let me know if it doesn't
    the code will create a sheet named master, you should start only with the sheets that you want consolidated since it will loop through all sheets, if you have sheets that you don't want consolidated then you will have to change the "for s =" line

    Sub Loop_Example()
        Dim Firstrow As Long
        Dim Lastrow As Long
        Dim Lrow As Long
    
    
    For s = 1 To Sheets.Count
    Sheets(s).Select
        'Sheets("MySheet")if you want
        With ActiveSheet
    
            'Set the first and last row to loop through
            If Sheets(s).Name = Sheets(1).Name Then
            Firstrow = 1
            Else:
            Firstrow = 2
            End If
            
            Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
    
            Rows(Firstrow & ":" & Lastrow).Copy
            
            Const strSheetName As String = "Master"
     
            Set wsTest = Nothing
            On Error Resume Next
            Set wsTest = ActiveWorkbook.Worksheets(strSheetName)
            On Error GoTo 0
     
            If wsTest Is Nothing Then
            Worksheets.Add after:=Sheets(Sheets.Count)
            ActiveSheet.Name = strSheetName
            End If
            
    
            
            Sheets("Master").Activate
            If Firstrow = 1 Then
            Lastrowa = ActiveSheet.Cells(.Rows.Count, "A").End(xlUp).Row
            Else:
            Lastrowa = ActiveSheet.Cells(.Rows.Count, "A").End(xlUp).Row + 1
            End If
            Range("A" & Lastrowa).Activate
            ActiveSheet.Paste
            Range("A1").Select
        End With
        Application.CutCopyMode = False
        
    Next
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1