VBA to copy based on heading not column

helpexcel

Well-known Member
Joined
Oct 21, 2009
Messages
656
I am using the following to copy colums of data from one sheet to another. Can I change the language so that it copies based on the headings in each row? So copy column with heading "Product" instead of "A4". This way if there is another spreadsheet that is sorted slightly different, the same data will get pulled, because it is looking for the heading and not just copying the column. Thanks.



Sheets("Raw Data").Select
Range(Range("A4"), Range("A4").End(xlDown)).Select
Selection.Copy
Sheets("Filtered").Select
Range("A8").Select
ActiveSheet.Paste
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
yes its possible but where is your raw data store which has header contents ?

or can post some sample of your data ?
 
Upvote 0
Code:
Range("4:4").Find(What:="Product").End(xlDown).Copy Sheets("Filtered").Range("A8")




...assuming your headers are in Row 4. If not, change 4:4 to 3:3 or something.
 
Upvote 0
thats why i asked you but you did not reply my questions ?
 
Upvote 0
Sorry. The raw data is compiled on the "raw data" spreadsheet. Headings start A3 and continue to BK3. The data could be 10 rows or 1000 rows.
Does that answer it? Thanks!
 
Upvote 0
That worked, but it only copied 1 cell. How do i copy everything in the row?

Do you mean everything in the column? Your question asked about copying specific columns based on their header. If you copy the entire row, then what is the point of isolating a particular column?
 
Upvote 0

Forum statistics

Threads
1,214,647
Messages
6,120,722
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