Merging worksheets together into a wordbook

T3l3cm0:123

New Member
Joined
Oct 4, 2013
Messages
2
Im trying to merge worksheets together into one workbook. I have a work book that has over 20 sheets. I has looking to create a macro that would merge sheets together (deepening on their name) into a separate workbook.
So far this is the code that I have got, it mergers all the sheets in the workbook together but I would like to merge them by name.

<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">Sub mergedata()Sheets(1).Activatelastrow = ActiveSheet.UsedRange.Rows.CountFor Each Sheet In SheetsIf Sheet.Index <> 1 ThenRowCount = Sheet.UsedRange.Rows.CountSheet.UsedRange.Copy Destination:=Sheets(1).Cells(lastrow + 1, 1)lastrow = lastrow + RowCountSheet.UsedRange.ClearEnd IfNext SheetEnd Sub</code></pre>
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I am unclear on you requirements. However, here is a modification to you code that will allow you to specify which sheets should be merged into sheet(1). Simply add the sheet names to the "Case" Line in the following code:

Code:
Sub mergedata()
    Sheets(1).Activate
    lastrow = ActiveSheet.UsedRange.Rows.Count
    For Each Sheet In Sheets
        Select Case LCase(Sheet.Name)
            Case "sheet2", "sheet5"
                RowCount = Sheet.UsedRange.Rows.Count
                Sheet.UsedRange.Copy Destination:=Sheets(1).Cells(lastrow + 1, 1)
                lastrow = lastrow + RowCount
                Sheet.UsedRange.Clear
        End Select
    Next Sheet
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,694
Messages
6,192,473
Members
453,726
Latest member
JoeH57

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