Using Column Header Name to Populate data

britsgal

Board Regular
Joined
Apr 8, 2014
Messages
75
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet where the first tab is a template with formulas pulling data from a 2nd sheet within the workbook. I receive a "dump" from another system, paste that into sheet 2 and the columns are auto-populated on sheet 1 using =A1="sheet 2" A1. The columns would be identical (the same header name) in order for this to work properly. Now someone has moved the columns around but I still need the columns in the original order on sheet 1. Is there a way to populate the columns on sheet 1 based on the column name and find the identical column name on sheet 2 to populate the column with the identical name on sheet one. As you can see from the below screen shot, I want the columns to reflect sheet 1 columns using the new position of sheet 2 columns (highlighted orange) but still pull the data into sheet 1 in the columns as shown. I hope this makes sense. NOTE: the columns in sheet 2 could change again as I do not control the system where the data is pulled from for sheet 2. Any help is appreciated.

1661349754977.png
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
My apologies.....using Office 365 on Windows. Updated profile with this information.
 
Upvote 0
Thanks for that. (y)
How about
Excel Formula:
=SORTBY(Sheet2!A2:J20,MATCH(Sheet2!A1:J1,A1:J1,0))
 
Upvote 0
Macro approach:
VBA Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim desWS As Worksheet, srcWS As Worksheet, LastRow As Long, lCol As Long, header As Range, x As Long, rng As Range
    Set srcWS = Sheets("Sheet2")
    Set desWS = Sheets("Sheet1")
    LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    lCol = desWS.Cells(1, Columns.Count).End(xlToLeft).Column
    For Each rng In desWS.Range("A1").Resize(, lCol)
        Set header = srcWS.Rows(1).Find(rng, LookIn:=xlValues, lookat:=xlWhole)
        If Not header Is Nothing Then
            srcWS.Range(srcWS.Cells(2, header.Column), srcWS.Cells(LastRow, header.Column)).Copy desWS.Cells(2, rng.Column)
        End If
    Next rng
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks everyone. I actually found another option from someone in my office. I appreciate everyone's help!
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top