Copy data under specific columns in sheet1 n paste to sheet2 under the same headers

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
 

Forum statistics

Threads
1,082,151
Messages
5,363,430
Members
400,736
Latest member
Aida

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top