Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

A Copy Paste Fail Excel VBA

Here is the code I used (triggered by a button on the "Sorts" worksheet):

Sub EOS_Archive_2()
Dim LCopyRow As Long
Dim LDistRow As Long
 
LCopyRow = Worksheets("Sorts").Cells(Sheet2.Rows.Count, 1).End(xlUp).Row
    
LDistRow = Worksheets("Sorts Archive").Cells(Sheet10.Rows.Count, 1).End(xlUp).Row + 1
 
Worksheets("Sorts").Range("C2: H" & LCopyRow).Copy _
Destination:=Worksheets("Sorts Archive").Range("B" & LDistRow)
 
End Sub

Here are the sheets I am copying from and to:

Sheet2 - "Sorts"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"Door" is in cell B1. The above sheet is "Sorts" It is desired to copy C2 through Hn (n being the last row of data in the range)

Sheet10 - "Sorts Archive"
The above sheet is "Sorts Archive" and this is the result of my code. Should paste the values into columns B through G. The code is run at the end of each day and will build data in the Sorts Archive sheet. All pasted data should start after the last row of data.

enter image description here

The above shows what the expected and desired result should be. Not sure why I am not getting the desired result. Any assistance would be appreciated.

>Solution :

  • Col A on Sorts sheet have only a used cell (A1), that is LCopyRow = 1. That’s the reason why only one row is copied over.
  • Please qualify Rows.Count with same sheet object.
  • You should locate the last data row by col 2 on both sheets.
LCopyRow = Worksheets("Sorts").Cells(Worksheets("Sorts").Rows.Count, "B").End(xlUp).Row
    
LDistRow = Worksheets("Sorts Archive").Cells(Worksheets("Sorts Archive").Rows.Count, "B").End(xlUp).Row + 1
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading