Copy Rows from all sheets to new workbook

helpexcel

Well-known Member
Joined
Oct 21, 2009
Messages
656
Hi - I'm looking to copy columns A-Z, Rows 20-30 on every sheet in WorkbookA. I want the sheet name put in A5 of WorkbookB, and then A20:Z30 in A6. There would be 2 blank rows and the next sheet name and range would be pasted into WorkbookB and so on. thanks!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I think we are missing several bits of information. What are the sheet names? how many sheets are there? what are the sheet names in the book you want posted in. For instance is Sheet 1 of workbook A supposed to be posted in Sheet 1 of workbook B. and Sheet 2 of workbook A to Sheet 2 of workbook B?
 
Upvote 0
There number of sheets in Workbook A is variable. I want all of the data from the sheets in workbookA copied to sheet1 in workbookB.
 
Upvote 0
okay, Sheet 1 A20:Z30 pastes in A6:Z16 of Workbook B. So you want A20:Z30 of Sheet 2 to drop 3 rows pasting a sheet name at A19 and then paste it A20:Z30 at A20?
 
Upvote 0
Basically i want to copy the data all of the sheets in WorkbookA on to one sheet in WorkbookB.
All of the data on the sheets in WorkbookA in the same place A20:Z30
I would also like to paste the sheet name the data was copied from in a cell above the copied data.
I would like the copied data to start in A5 of sheet1 in WorkbookB.
 
Upvote 0
Place this macro in a standard module in WorkBookA and run it from there. Change the workbook name and sheet name to suit your needs. Make sure both workbooks are open.
Code:
Sub CopyRange()
    Application.ScreenUpdating = False
    Dim LastRow As Long, ws As Worksheet, desWS As Worksheet, x As Long: x = 6
    Set desWS = Workbooks("[COLOR="#FF0000"]WorkbookB.xlsx[/COLOR]").Sheets("[COLOR="#FF0000"]Sheet1[/COLOR]")
    For Each ws In Sheets
        LastRow = desWS.Range("A" & desWS.Rows.Count).End(xlUp).Row
        If LastRow < 5 Then
            desWS.Range("A5") = ws.Name
            ws.Range("A20:Z30").Copy desWS.Range("A6")
        Else
            With desWS
                .Cells(.Rows.Count, "A").End(xlUp).Offset(3, 0) = ws.Name
                ws.Range("A20:Z30").Copy .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
            End With
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
thanks Mumps! I had to change For Each ws In Sheets to For Each ws In ThisWorkbook.Sheets and it works great. I need to play with it a little, because I want the code in WorkbookB.
 
Upvote 0
See if this works for you:
Code:
Sub CopyRange()
    Application.ScreenUpdating = False
    Dim LastRow As Long, ws As Worksheet, srcWS As Workbook, desWS As Worksheet
    Set srcWB = Workbooks("WorkbookA.xlsx")
    Set desWS = Sheets("Sheet1")
    For Each ws In srcWB.Sheets
        LastRow = desWS.Range("A" & desWS.Rows.Count).End(xlUp).Row
        If LastRow < 5 Then
            desWS.Range("A5") = ws.Name
            ws.Range("A20:Z30").Copy desWS.Range("A6")
        Else
            With desWS
                .Cells(.Rows.Count, "A").End(xlUp).Offset(3, 0) = ws.Name
                ws.Range("A20:Z30").Copy .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
            End With
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,836
Messages
6,181,252
Members
453,028
Latest member
letswriteafairytale

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