Copy data to another sheet last row

yayakele

New Member
Joined
Sep 17, 2023
Messages
4
Office Version
  1. 2021
Platform
  1. Windows
Hi...I want to copy data from one sheet,ie "input data" and paste them on another sheet, ie "data" , i need to paste to the last row in that datasheet. the source data range is varied, sometime like range B6:N6, sometimes like range B6:N20. How do i write the code to paste the selection to the blank row under exist data, defined by column B? can i make a loop formula so the source data can copy and paste automatically without determine the range to copy and paste
 

Attachments

  • Screenshot (134).png
    Screenshot (134).png
    46 KB · Views: 32
  • Screenshot (133).png
    Screenshot (133).png
    15 KB · Views: 32

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Which image is of which sheet? The second image has no row numbers and limited columns shown, so it is hard to follow exactly what ranges you are trying to copy where.

If you wanted to copy from cell B6 to the last row and copy over to column N, then assuming column B always has an entry for every row with data, you can dynamically find the last row like this:
VBA Code:
Dim lr as Long
lr = Sheets("input data").Cells(Rows.Count, "B")
so then you could copy that range dynamically like this:
VBA Code:
Sheets("input data").Range("B6:N" & lr).Copy

Likewise, you can find the last populated column in a row on your destination sheet. So if we were to look at column B on your "data" sheet to find the last row with data in that column, it would look like this:
VBA Code:
Dim lr2 as Long
lr2 = Sheets("data").Cells(Rows.Count, "B")

Then, when we paste, simply add one to that row number to past on the next line, i.e.
VBA Code:
Sheets("data").Activate
Range("B" + lr2 + 1).Select
ActiveSheet.Paste

Hope that helps!
Let us know if you have any questions.
 
Upvote 0

Forum statistics

Threads
1,223,704
Messages
6,173,984
Members
452,540
Latest member
haasro02

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