+ Reply to Thread
Results 1 to 8 of 8

Combine multiple sheets in Master

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-21-2018
    Location
    Romania
    MS-Off Ver
    2010
    Posts
    178

    Combine multiple sheets in Master

    Hy! How can to combine more sheets in one master, without duplicates?

  2. #2
    Forum Contributor
    Join Date
    08-21-2018
    Location
    Romania
    MS-Off Ver
    2010
    Posts
    178

    Re: Combine multiple sheets in Master

    some help, please?

  3. #3
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Combine multiple sheets in Master

    You will need to attach a sample workbook with the sheets in question.

    Go Advanced -> Manage Attachments -> Upload

  4. #4
    Forum Contributor
    Join Date
    08-21-2018
    Location
    Romania
    MS-Off Ver
    2010
    Posts
    178

    Re: Combine multiple sheets in Master

    is copy just col A and col B. i want to copy all columns
    Attached Files Attached Files

  5. #5
    Forum Contributor banaanas's Avatar
    Join Date
    08-26-2014
    Location
    Finland
    MS-Off Ver
    2016
    Posts
    199

    Re: Combine multiple sheets in Master

    Put this into a module (not a worksheet)
    Option Explicit 'Always start your code with this. You have to declare all variables with DIM and REDIM statements, and that makes the code more robust
    
    Sub CombineSheets()
    Application.ScreenUpdating = False 'Disable screenupdates. Makes the code faster.
    
    Dim wb As Workbook 'This workbook
    Dim ws As Worksheet 'A worksheet
    Dim masterWs As Worksheet
    Dim rng As Range 'Range to be copied
    Dim lastrow As Long 'Helper to store lastrow on a sheet
    
    Set wb = ThisWorkbook 'Store this workbook into a variable
    Set masterWs = wb.Worksheets("Master") 'Set master WS
    
    For Each ws In wb.Worksheets 'Loop all worksheets
        If ws.Name <> "Master" Then 'If worksheet is not the mastersheet
            lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row 'Find the lastrow on current worksheet
            ws.Range("A3:AG" & lastrow).Copy
            lastrow = masterWs.Cells(Rows.Count, "A").End(xlUp).Row + 1 'Find first empty row on master
            masterWs.Range("A" & lastrow).PasteSpecial xlPasteValues 'Paste range
        End If
    Next ws
    
    Application.ScreenUpdating = True 'Enable screenupdates again
    MsgBox "Done" 'tell user
    End Sub
    Tuomas "Banaanas" Savonius
    Trying to give back now when I actually can do some VBA

  6. #6
    Forum Contributor
    Join Date
    08-21-2018
    Location
    Romania
    MS-Off Ver
    2010
    Posts
    178

    Re: Combine multiple sheets in Master

    if i run more time the module, in master is duplicated the data from sheets

  7. #7
    Forum Contributor banaanas's Avatar
    Join Date
    08-26-2014
    Location
    Finland
    MS-Off Ver
    2016
    Posts
    199

    Re: Combine multiple sheets in Master

    Modified to cleat Master WS

    Option Explicit                        'Always start your code with this. You have to declare all variables with DIM and REDIM statements, and that makes the code more robust
    
    Sub CombineSheets()
        Application.ScreenUpdating = False 'Disable screenupdates. Makes the code faster.
    
        Dim wb         As Workbook         'This workbook
        Dim ws         As Worksheet        'A worksheet
        Dim masterWs   As Worksheet
        Dim rng        As Range            'Range to be copied
        Dim lastrow    As Long             'Helper to store lastrow on a sheet
    
        Set wb = ThisWorkbook              'Store this workbook into a variable
        Set masterWs = wb.Worksheets("Master") 'Set master WS
    
        lastrow = masterWs.Cells(Rows.Count, "A").End(xlUp).Row 'Find first non empty row on master
        
        If lastrow > 2 Then                'If we have data on worksheet
            masterWs.Range("A3:AG" & lastrow).ClearContents 'Clear the masterWS first
        End If
        
        For Each ws In wb.Worksheets       'Loop all worksheets
            If ws.Name <> "Master" Then    'If worksheet is not the mastersheet
                lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row 'Find the lastrow on current worksheet
                ws.Range("A3:AG" & lastrow).Copy
                lastrow = masterWs.Cells(Rows.Count, "A").End(xlUp).Row + 1 'Find first empty row on master
                masterWs.Range("A" & lastrow).PasteSpecial xlPasteValues 'Paste range
            End If
        Next ws
    
        Application.ScreenUpdating = True  'Enable screenupdates again
        MsgBox "Done"                      'tell user
    End Sub

  8. #8
    Forum Contributor
    Join Date
    08-21-2018
    Location
    Romania
    MS-Off Ver
    2010
    Posts
    178

    Re: Combine multiple sheets in Master

    is working. thank you very much

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 07-24-2017, 01:14 PM
  2. Combine columns data from multiple sheets to existing master sheet via cell value
    By 253.Asmo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-16-2015, 12:13 PM
  3. Combine multiple sheets into master sheet, and include sheer name
    By FDibbins in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-18-2015, 10:32 PM
  4. Combine multiple sheets into one master doucument.
    By postrander in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-29-2014, 07:54 PM
  5. Combine folder sheets to one master sheet
    By rchure in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-25-2014, 01:11 AM
  6. Combine several workbooks containing data in multiple sheets into a master Workbook
    By sunrize9 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-09-2014, 09:10 PM
  7. Anyway to combine multiple sheets into master?
    By rbzurich in forum Excel General
    Replies: 1
    Last Post: 06-12-2007, 11:13 AM

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