Solved

how to maps columns from one spreadsheet to another.

Posted on 2014-02-24
9
883 Views
Last Modified: 2014-03-20
Hi,

I have worksheet 1 with lot of data in it.

I have worksheet 2 with no data but the same column headers as worksheet 1.

is it possible to map columns from worksheet 1 to worksheet 2 so that data from worksheet 1 goes into the right columns in worksheet 2.

please note that the column headers order is different in both worksheets and i want to copy data from worksheet 1 to worksheet 2 but in the right columns and dynamically.

Not like copy and pasting column by column from worksheet 1 to worksheet 2.
0
Comment
Question by:AmmarDJ
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39881883
Please upload a sample file.
0
 

Author Comment

by:AmmarDJ
ID: 39881887
i cannot upload a file since it is confidential data.

but would be glad if you could just give some  hints.
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39881891
Use fictitious data, that part really isn't important, it's the layout that counts.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 39881913
Sub Map()

    Dim Sh1 As Worksheet, Sh2 As Worksheet
    Dim HeadersOne() As String
    Dim HeadersTwo() As String

    With ThisWorkbook
        Set Sh1 = .Sheets("Sheet1") 'Modify as necessary.
        Set Sh2 = .Sheets("Sheet2") 'Modify as necessary.
    End With

    HeadersOne() = Split("applicationname,applicationid,number", ",")
    HeadersTwo() = Split("appname,appid,num", ",")

    For HeaderIter = 1 To 3
        SCol = GetColMatched(Sh1, HeadersOne(HeaderIter - 1))
        TCol = GetColMatched(Sh2, HeadersTwo(HeaderIter - 1))
        LRow = GetLastRowMatched(Sh1, HeadersOne(HeaderIter - 1))

        For Iter = 2 To LRow
            Sh2.Cells(Iter, TCol).Value = Sh1.Cells(Iter, SCol).Value
        Next Iter
    Next HeaderIter

End Sub

Function GetLastRowMatched(Sh As Worksheet, Header As String) As Long
    ColIndex = Application.Match(Header, Sh.Rows(1), 0)
    GetLastRowMatched = Sh.Cells(Rows.Count, ColIndex).End(xlUp).Row
End Function

Function GetColMatched(Sh As Worksheet, Header As String) As Long
    ColIndex = Application.Match(Header, Sh.Rows(1), 0)
    GetColMatched = ColIndex
End Function

Open in new window


See the above example will help you I guess . If you give some raw data we can work out on your data.
Refer this from link
http://stackoverflow.com/questions/21130328/mapping-column-headers-from-one-sheet-to-another
0
 
LVL 3

Expert Comment

by:Sreeram
ID: 39881919
Try this

In the Respective column of Worksheet 2

=WorkSheet2!Respective Column name

Ex:

=Sheet1!E12
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39881956
If the data starts in A2 and the column headers are in row 1 then you can use this formula

=INDEX(Sheet1!$1:$1048576,ROW(),MATCH(B$1,Sheet1!$1:$1,0))

copied down and across.
ColumnMap.xlsx
0
 

Author Comment

by:AmmarDJ
ID: 39881979
saqib hussain.

thanks for the post.

It works fine.

I believe it should work for any number of columns are rows? correct? and for all types of data, numeric as well as character
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39882130
Give it a try and then come back if you need further assistance.
0
 
LVL 33

Accepted Solution

by:
Rob Henson earned 500 total points
ID: 39882345
Assuming the headers are the same text but in different order, you can also use the Advanced Filter function.

Set data as source data, set destination as destination sheet with headers already populated. The criteria could potentially just be one header and a blank cell underneath it, assuming you have one column that will be populated for all records.

Thanks
Rob H
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question