Copy different area and paste to another sheet

haseft

Active Member
Joined
Jun 10, 2014
Messages
321
hej,
copy with variable lastrow dosent work.
VBA Code:
Sub Makro5()
'
Dim sht As Worksheet
Dim lastrow As Long
Set sht = ThisWorkbook.Worksheets("Sheet1")
lastrow = sht.Cells(sht.Rows.Count, "B").End(xlUp).Row '

Worksheets("Sheet1").Range("A2:AF& lastrow,AG2:AG& lastrow,AJ2:AJ& lastrow").Copy Worksheets("Sheet3").Range("A2")

'Worksheets("Sheet1").Range("A2:AF400,AG2:AG400,AJ2:AJ400").Copy Worksheets("Sheet3").Range("A2")'    works
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try it like
VBA Code:
Worksheets("Sheet1").Range("A2:AG" & lastrow & ",AJ2:AJ" & lastrow).Copy Worksheets("Sheet3").Range("A2")
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,477
Messages
6,125,036
Members
449,205
Latest member
Eggy66

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