Copy paste from one sheet to another problem

adnan1975

New Member
Joined
Aug 24, 2017
Messages
38
I have problem with the following code. I am trying to copy data from one sheet "rp" and paste it into "peim" provided the if conditions is met. The code runs fine except it copy paste over the same cells in the destination sheet.
So there are about 6 entries in the source sheet and i want all 6 entries to be pasted in destination sheet in rows. But my code just over writes the same row with all 6 entries and only show the last entry. I dont know who to make it work so that it copy and paste paste each entry in the next available row.

Code:
Sub final_Report()




    Dim rng As Range
    Dim PEIM_Report As Worksheet
    Dim Report As Worksheet
    Dim eDate As Date
    Dim sDate As Date
    Dim Sformula As String
    


Set peim = ThisWorkbook.Sheets("PEIM_Report")
Set rp = ThisWorkbook.Sheets("Report")


lr = rp.Cells(Rows.Count, 1).End(xlUp).Row
lrp = peim.Cells(Rows.Count, 1).End(xlUp).Row


       
    For x = 6 To lr
       If rp.Cells(x, 14).Value = "Yes" Then
      rp.Range("A" & x, "F" & x).Copy
    peim.Cells(lrp + 1, 1).PasteSpecial xlPasteValues
        Application.CutCopyMode = False
        End If
    Next x


End Sub

Thanks in advance for any help.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Add this line as shown
Code:
peim.Cells(lrp + 1, 1).PasteSpecial xlPasteValues
[COLOR=#0000ff]lrp=lrp+1[/COLOR]
Application.CutCopyMode = False
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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