Copying unknown number of rows from one worksheet to another

sbecker61

Board Regular
Joined
Dec 29, 2009
Messages
52
I have one workbook with 3 worksheets. The 1st sheet is the master and the rest are the "subordinate" spreadsheets. In worksheets 2 thru 3 i have information (cells) about a customer. I may have one line of documentation per sheet, I may have 100 lines of documentation. It varies from week to week. For example,

Sheet 2

AAAAA BBBBB CCCCC DDDDD
EEEEE FFFFF GGGGG HHHHH

Sheet 3

IIIIIIII JJJJJJ KKKKKK MMMMM
NNNN OOOO PPPPPP QQQQQQ
RRRR SSSS TTTTT UUUUUU

I want the master spreadsheet to show:

AAAAA BBBBB CCCCC DDDDD
EEEEE FFFFF GGGGG HHHHH
IIIIIIII JJJJJJ KKKKKK MMMMM
NNNN OOOO PPPPPP QQQQQQ
RRRR SSSS TTTTT UUUUUU

I don't wany any spaces at all between rows. The final result should be a combination of all the sheets (2 thru x) in my workbook. BTW, I may end up having up to 20 tabs / sheets in this workbook eventually. My challenge is (and has been) how do I account for the different numbers of rows in each worksheet and make sure I have one continous / contiguous set of data in my master sheet? Sure, I can copy and paste manually but is there a VBA way to do this? I'm sure the Excel masters here have done this before.

Thanks in advance.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try this: change Master to the name of the master sheet

Rich (BB code):
Sub Cpy()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> "Master" Then
        ws.UsedRange.Copy Destination:=Sheets("Master").Range("A" & Rows.Count).End(xlUp).Offset(1)
    End If
Next ws
End Sub
 
Upvote 0
Hi and thank you so much for responding,

My bad. I didn't tell you everything. My info that will be copied always lies in cells a37:g37 to a45:g45. I only want to copy the cells that are not empty to the master spreadsheet.

I know your solution copies everything from the worksheet. I only want to copy those specific cells above.

Please help and thanks again.

Steve
 
Upvote 0
Try

Code:
Sub Cpy()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> "Master" Then
        ws.Range("A37:G45").Copy Destination:=Sheets("Master").Range("A" & Rows.Count).End(xlUp).Offset(1)
    End If
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,676
Members
449,463
Latest member
Jojomen56

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