+ Reply to Thread
Results 1 to 3 of 3

Merge worksheets

Hybrid View

  1. #1
    Registered User
    Join Date
    03-13-2011
    Location
    Isle of Man
    MS-Off Ver
    Excel 2003
    Posts
    5

    Merge worksheets

    Hi, Please can some help me. I have a workbook with multiple sheets which i am basically trying to merge into one. (Each worksheet has the same row headings) I know i could copy and paste but i have about 15 workbooks all together some with more than 15 sheets.
    Can anyone please explain in simple terms how to do this plesae?
    Thanks in advance.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Merge worksheets

    Here's some code that you can adapt
    
    '---------------------------------------------------------------------------------------
    ' Module    : Module1
    ' DateTime  : 09/05/2007 08:43
    ' Author    : Roy Cox (royUK)
    ' Website   :for more examples and Excel Consulting
    ' Purpose   : combine data from multiple sheets to one
    ' Disclaimer; This code is offered as is with no guarantees. You may use it in your
    '             projects but please leave this header intact.
    
    Option Explicit
    
    
    '---------------------------------------------------------------------------------------
    ' Procedure : Combinedata
    ' Author    : Roy Cox
    ' Website   : www.excel-it.com
    ' Date      : 10/10/2010
    ' Purpose   : Combine data from all sheets to a master sheet
    '---------------------------------------------------------------------------------------
    '
    Sub Combinedata()
    
        Dim ws As Worksheet
        Dim wsmain As Worksheet
        Dim DataRng As Range
        Dim Rw As Long
        Dim Cnt As Integer
        Const ShtName As String = "Master" '<-destination sheet here
        Cnt = 1
    
        Set wsmain = Worksheets(ShtName)
        wsmain.Cells.Clear
        For Each ws In ThisWorkbook.Worksheets
            If ws.Name <> wsmain.Name Then
                If Cnt = 1 Then
                    Set DataRng = ws.Cells(2, 1).CurrentRegion
                    DataRng.copy wsmain.Cells(1, 1)
                Else: Rw = wsmain.Cells(Rows.Count, 1).End(xlUp).Row + 1
                MsgBox ws.Name & Rw
                Set DataRng = ws.Cells(2, 1).CurrentRegion
                    'don't copy header rows
                    DataRng.Offset(1, 0).Resize(DataRng.Rows.Count - 1, _
                                                DataRng.Columns.Count).copy ActiveSheet.Cells(Rw, 1)
                End If
            End If
            Cnt = Cnt + 1
        Next ws
    
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    03-13-2011
    Location
    Isle of Man
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Merge worksheets

    Ok, thanks. i will have a go. not to sure where or what to do with code though.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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