?
Solved

how to maps columns from one spreadsheet to another.

Posted on 2014-02-24
9
Medium Priority
?
1,135 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
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.

719 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