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!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try

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

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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