Copy and Paste Rows VBA and loop through all sheets...

bran8989

New Member
Joined
Sep 14, 2018
Messages
23
Need help, here is my code.. I want it to loop through all available sheets, but on the i + 1 sheets I want it to paste to the next available empty row (i.e. I need "i" to be changing to in my range)..

Sub Paste_NextRow()


Dim wsCopy As Worksheet
Dim wsPaste As Worksheet

i = Sheets.Count


For i = 2 To Sheets.Count

Set wsCopy = Sheets(i)
Set shtInput = Sheets(1)


If i = 2 Then
shtInput.Range("C" & i).Value = wsCopy.Range("OA_CPA").Value
shtInput.Range("D" & i).Value = wsCopy.Range("OA_CPA").Value
shtInput.Range("E" & i).Value = wsCopy.Range("OA_CPA").Value
shtInput.Range("F" & i).Value = wsCopy.Range("OA_CPA").Value

End If


Next i


End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Welcome to the board. Not tested, save your file before running macro, however, try:
Code:
Sub Paste_NextRow()

    Dim x       As Long

    Application.ScreenUpdating = False
    
    With Sheets(1)
        For x = 2 To Worksheets.Count
            .Cells(.Cells(.Rows.Count, 3).End(xlUp).Row + 1, 3).Resize(, 4).Value = Sheets(x).Range("OA_CPA").Value
        Next x
    End With
    
    Application.ScreenUpdating = True

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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