Excel copy contents in a specified range to the last row in another range

Hello,

In worksheet A, there is a range A1: J20
in Worksheet B, there is a range A: J

Each day new content is added to Worksheet A replacing the previous one. For example this content could be A1:J4, or A1:J16. The macro should just copy the latest content, not the whole range, and past it to the last row in Worksheet B.

Example:
Day1: copy WS A, range(A1:j4) to WS B, range(A1:J4)
Day2: copy WS A, range(A1:J2) to WS B, range(A5:J7)  (i.e. copy just the content and find last row and paste)
Day3. copy WS A, range(A1:J10) to WS B, range(A8:J17)

And so on......

Thanks,
CC
CC10Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
Assuming you want to copy data from Sheet1 to Sheet2...

Sub copydata()
    Dim ws As Worksheet, ws1 As Worksheet
    Dim lrow As Long, lr As Long
    Set ws = Sheets("Sheet1")
    Set ws1 = Sheets("Sheet2")

    lrow = ws.Cells(Cells.Rows.Count, "A").End(xlUp).Row
    lr = ws1.Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1

    ws.Range("A1:J" & lrow).Copy ws1.Range("A" & lr)


End Sub

Open in new window


Saurabh,,,
0
RonBudget AnalystCommented:
Beat me to it...
I like to reference sheet names by their object name instead of the caption, which can change, so...in the VBA Editor on the left you'll see your sheets named as such: Sheet1 (Sheet1), where the first is the object name and inside the parentheses is the text you see as the tab or sheet name.

So...if Worksheet A is the object Sheet1 with your source data, and Worksheet B is the object Sheet2 where the new data is to be appended, then I also like the elegance of the Range/Copy method where the copy destination is on the same line as the source range: Range(something).Copy Destination

Sub CopyData()
Dim lNewRow As Long

lNewRow = Sheet2.Range("A100000").End(xlUp).Row + 1
Sheet1.Range("A1:J14").Copy Sheet2.Cells(lNewRow, 1)

End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CC10Author Commented:
Both solutions work perfectly. Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.