Copy specific columns with variable row count to new worksheet.

msquared99

Board Regular
Joined
Mar 8, 2012
Messages
52
I have been trying to figure out how to copy specific columns with variable rows to a new workbook. My raw data workbook has data in columns A:Y. My macro (which is a stand alone) sorts on column R to get the data I want to copy at the top.

What I want to do is copy columns A, C, R:T rows 2:lastRow, where lastRow is a variable, into my master template in columns A:E. Sometimes the rows in the raw data workbook could be 10 rows and other times it could be 50 rows. Row 1 has column headers in it.

Example:

Workbooks("Raw Data").Worksheets(1).Activate
Worksheets(1).Range("A2:A", "C2:C", "R2:T" & lastRow).Copy _
Destination:=Workbooks("Master Template").Worksheets("Delivery").Range("A5")

Many thanks!
 

Some videos you may like

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Try

Intersect(Worksheets(1).Range("2:" & lastrow), Worksheets(1).Range("A:A, C:C, R:T")).Copy
 

Watch MrExcel Video

Forum statistics

Threads
1,123,156
Messages
5,600,040
Members
414,357
Latest member
Gemma_R

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
Top