VBA Code copy pasting to wrong row

Dokat

Active Member
Joined
Jan 19, 2015
Messages
304
Office Version
  1. 365
Hi,

I have below code where i'd like to clear all rows below 7,345 and paste the newly copied range starting row #7346. Code copy paste and appends 2 workbooks into third one and works fine however the issue is it pastes first row twice starting row 7346. So basically row 7346 and 7347 has duplicate values and the rest is correct. Appreciate anyones help!


VBA Code:
Private Sub CopyPasteMTDYTD()
On Error Resume Next
Application.ScreenUpdating = False

Dim Lrs As Long
Lrs = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
Range("A7345:F" & Lrs).Offset(1).Clear

Workbooks.Open ("C:\Users\dokat\OneDrive - BIC\BIC\Power BI\Trade Report\Montly Data\2017-2022 6 Year Trended PnL by L3 - YTD February.xlsm")

Dim Lr  As Long
Dim ws As Worksheet
Set ws = Workbooks("2017-2022 6 Year Trended PnL by L3 - YTD February.xlsm").Worksheets("Summary")
Lr = ws.Cells(Rows.Count, 1).End(xlUp).Row

ws.Range("A1:F" & Lr).Copy

Workbooks("Sta P&L Test.xlsm").Sheets("Sta P&L").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues

Application.CutCopyMode = False

Workbooks("2017-2022 6 Year Trended PnL by L3 - YTD February.xlsm").Close

Workbooks.Open ("C:\Users\dokat\OneDrive - BIC\BIC\Power BI\Trade Report\Montly Data\2017-2022 6 Year Trended PnL by L3 - February.xlsm")

Dim Lrm  As Long
Dim wsm As Worksheet
Set wsm = Workbooks("2017-2022 6 Year Trended PnL by L3 - February.xlsm").Worksheets("Summary")
Lrm = wsm.Cells(Rows.Count, 1).End(xlUp).Row

wsm.Range("A2:F" & Lrm).Copy

Workbooks("Sta P&L Test.xlsm").Sheets("Sta P&L").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues

Application.CutCopyMode = False

Workbooks("2017-2022 6 Year Trended PnL by L3 - February.xlsm").Close


Application.ScreenUpdating = True

End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I cannot seem to produce the results you are seeing.
Have you checked your source data to see if there is a duplication in the first few rows? Merged cells? or maybe a hidden row?
When I ran your script it produced the results with no duplication in any of the Rows.
 
Upvote 0
I cannot seem to produce the results you are seeing.
Have you checked your source data to see if there is a duplication in the first few rows? Merged cells? or maybe a hidden row?
When I ran your script it produced the results with no duplication in any of the Rows.
Yes i did double checked there is no duplication, hidden or merged rows. Its just weird that it still creates duplication.
.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
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