Solved

how to maps columns from one spreadsheet to another.

Posted on 2014-02-24
9
804 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

920 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

13 Experts available now in Live!

Get 1:1 Help Now