Solved

how to maps columns from one spreadsheet to another.

Posted on 2014-02-24
9
773 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 26

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 26

Expert Comment

by:MacroShadow
ID: 39881891
Use fictitious data, that part really isn't important, it's the layout that counts.
0
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 31

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now