Solved

how to maps columns from one spreadsheet to another.

Posted on 2014-02-24
9
842 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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 32

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

831 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