ShyamExcel
New Member
- Joined
- Mar 8, 2012
- Messages
- 1
I'm pretty new to VBA and I'm trying to automate a few things and the task at hand is like this:
Two sheets in my workbook 'marketing.xlsm' -Sheet1 and Sheet2. Sheet1 is the source sheet containing between 5 and 15 columns at different instances (import different CSV files weekly) but they will always contain the 4 columns alpha, beta, gamma, and theta in no particular order but always on row 2.
Sheet2 is my destination sheet which will have only the 4 headers on row 2 for the four columns - alpha, beta, gamma and theta. Only headers in this blank sheet on row 2. No data under them.
What I want to do is create a VBA code to look up each of header values in row 2 of sheet2, search sheet1 in row 2 for the cell text (say, alpha), copy the data from the corresponding column and paste the data without header into sheet 2. So in effect, we would have copied data underneath column 'alpha' in sheet1 into column 'alpha' in sheet2. (if alpha column was in B2 in sheet1 and had 100 data points, we would have copied B3:B103 into sheet 2 under column 'alpha'.
Alternative source:
Since the data for sheet1 comes from a web report as CSV, I'm also thinking, instead of importing the data into sheet1, if the VBA code can look up the file named 'data.csv' and sheet1 in it, extract the data and paste under the 4 columns listed in sheet2 of my destination workbook (marketing.xlsm) directly, that would be even better.
The critical points are
1. All column headers in sheet1 can occur anywhere in row 2, no fixed position. So alpha can be at C2, D2, or G2 or such.
2. The number of data points under each column can vary too (10 to 10000) but all columns will have the same number of data points as its a table.
Appreciate your suggestions and any assistance you can provide!
Shyam
Two sheets in my workbook 'marketing.xlsm' -Sheet1 and Sheet2. Sheet1 is the source sheet containing between 5 and 15 columns at different instances (import different CSV files weekly) but they will always contain the 4 columns alpha, beta, gamma, and theta in no particular order but always on row 2.
Sheet2 is my destination sheet which will have only the 4 headers on row 2 for the four columns - alpha, beta, gamma and theta. Only headers in this blank sheet on row 2. No data under them.
What I want to do is create a VBA code to look up each of header values in row 2 of sheet2, search sheet1 in row 2 for the cell text (say, alpha), copy the data from the corresponding column and paste the data without header into sheet 2. So in effect, we would have copied data underneath column 'alpha' in sheet1 into column 'alpha' in sheet2. (if alpha column was in B2 in sheet1 and had 100 data points, we would have copied B3:B103 into sheet 2 under column 'alpha'.
Alternative source:
Since the data for sheet1 comes from a web report as CSV, I'm also thinking, instead of importing the data into sheet1, if the VBA code can look up the file named 'data.csv' and sheet1 in it, extract the data and paste under the 4 columns listed in sheet2 of my destination workbook (marketing.xlsm) directly, that would be even better.
The critical points are
1. All column headers in sheet1 can occur anywhere in row 2, no fixed position. So alpha can be at C2, D2, or G2 or such.
2. The number of data points under each column can vary too (10 to 10000) but all columns will have the same number of data points as its a table.
Appreciate your suggestions and any assistance you can provide!
Shyam