VBA to copy and paste multiple sheets

cruyff73

New Member
Joined
Oct 7, 2016
Messages
32
Hi,

I'm trying to consolidate info held on 128 sheets using the code below but it doesn't work. Can anyone suggest a correction?

Sub CombineSheets()
Dim rng As Range
Set rng = Sheets("master log").Range("A2:s25000")
Sheets("master log").Activate
rng.ClearContents
Dim i As Integer
For i = 1 To 128
Sheets(i).Range("a7:s2500").Copy
lastrow = Sheets("master log").Cells(Sheets("master log").Rows.Count, 1).End(xlUp).Row + 1
Sheets("master log").Cells(lastrow, 1).Paste
Application.clearcopymode
Application.DisplayAlerts = False
Next i
Range("A1").Select
End Sub

Thanks a lot
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try

Code:
Sub CombineSheets()
    Dim ws As Worksheet, sh As Worksheet, i As Integer, lastRow As Long
    Set ws = Sheets("master log")
    ws.Range("A2:s25000").ClearContents
    For i = 1 To 128
        Set sh = Sheets(i)
        lastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1
        sh.Range("a7:s2500").Copy ws.Cells(lastRow, 1)
    Next i
    ws.Activate
    Range("A1").Select
End Sub

:warning: Assumes "master log" is sheet number 129 (or greater) in the same workbook
 
Upvote 0
Try making these 2 changes
Code:
Sheets("master log").Cells(lastrow, 1).[COLOR=#ff0000]PasteSpecial[/COLOR]
Application.[COLOR=#ff0000]CutCopyMode = False
[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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