0
votes

I'm attempting to write a macro that will copy a range of cells from a sheet, paste them into a sheet ("Bulksheet") that will contain all pasted data, then move on to the next tab after the first sheet. This needs to be done for 40+ tabs. Luckily, the data is in the same place in each tab, including the Bulksheet tab.

I can easily get this to apply to one tab, but returning to the first active tab and then moving on to the next is giving me no end of trouble.

Ex. code (shortened to the crucial bit). At the bottom where Next is would be where I need to move to the next sheet and do the same function, returning to "Bulksheet" and pasting in the next empty cell in column C.:

Sub
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Activate
Range("C100:F103").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Bulksheet").Select
Range("D1").End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
Next
End Sub
2
Please don't use [macros] for MS Office or VBA. macros tag wikiByron Wall

2 Answers

0
votes

Try looping through the sheets using an index value instead.

Sub
Dim i as integer
For i = 1 to worksheets.count
sheets(i).Activate
if activesheet.name <> "Bulksheet" then
Range("C100:F103").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Bulksheet").Select
Range("D1").End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
end if
Next
End Sub
0
votes

Try this:

enter image description here

enter image description here

Sub CopyToBulksheet()
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
    If ws.Name <> "Bulksheet" Then
        ws.Activate
        Range("C1:F10").Copy

        Sheets("Bulksheet").Select
        Range("D" & Cells.Rows.Count).End(xlUp).Offset(1, 0).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    End If
Next
End Sub