VBA code - Copy Range with last row used

Ostoop

New Member
Joined
Sep 19, 2014
Messages
5
I currently have the code below which does all I want except for one thing. Currently it copes a range of data in "Data" sheet and pastes it as values in sheet "JE" starting at cell C22:K22.
Code:
Sub CopyData()
    Sheets("Data").Range("B2:J17").Copy
    Sheets("JE").Range("C22").PasteSpecial xlPasteValues
End Sub

Cell B2 in the range is always the same, also column J, however row 17 can differ, the range should be up to the last row used based in column B.
So range can be B2:J10 or B2:B200 depending on how many rows exist.

Any ideas?

Thank you!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Is the data always being pasted into JE!C22? ie being overwritten each time?
 
Upvote 0
Try this

Code:
Sub CopyData()
Dim a As Integer
    a = Sheets("Data").Range("B" & Rows.Count).End(xlUp).Row
    Sheets("Data").Range("B2:J" & a).Copy
    Sheets("JE").Range("C22").PasteSpecial xlPasteValues
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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