• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Copy specific columns with dynamic row range.

I had a situation where my raw data workbook contained data in columns A:Y. In column R, the data could vary from 5 to several hundred rows and was the only row where if sorted, data would be in only say 50 of 100 rows. The column R data was what I was interested in. So, how do I copy only columns A, C and R to the last row in column R and put it into my master workbook in columns A:C? My macro first sorts by column R.


Solution:


'Application.Union(Range("A2:A" & lastRow),Range("C2:C" & lastRow),Range("R2:R" & lastRow)).Copy _

Destination:=Workbooks("Master.xlsx").Sheets("Data").Range("A2")'


Not sure if anyone else has this same situation but this code works well.
 
Back
Top