Excel: Wanted - Code to map fields and update data between two lists

I need to move table data from one excel list to another, based on a set of
field name mappings from one list to the other maintained on a third sheet.

I understand that the LOOKUP function will return the corresponding field name for the other sheet, but how do I move the data automatically?

I'd appreciate any pointers / sample code.

For e.g.,

Sheet 1 contains columns titled 'YTD' and 'Mech'
Sheet 2 contains columns titled 'Budget' and 'Spent'
Sheet 3 contains two columns holding the mapping list:
YTD -> Spent
Mech -> Budget

I want to automatically move data in the 'YTD' column on sheet 1 to the corresponding column in sheet 2 (the column 'Spent' in this case) based on the field name mappings maintained in sheet 3.

I hope the purpose is clear. Of course, my sheets have many more columns.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi Nasriram,

Let's say, your headers on sheet 1 are on line 1 in  the range A1:G1 (7 columns), you give it a name 'Headers' (Select headers row, go to menu Bar/Insert/Name/ Type "Headers" in the 'names in worksheet box', and click OK).

The Mapping list is on sheet 3, for example in range B1:C5 (that's 5 mappings). In this mapping list, for my below formula to work, the column labels of sheet2 must be in left column and the source column labels of sheet1 must be in right column.

Then in cell B2 of sheet 2 (the header names must be on line 1), enter this formula, and copy it down to all other cells.


That should do it.

If you enter a line, where in sheet1 no data is entered yet, the formula will return a #REF result. That's normal.
If you want to transform this error message into a blank, transform the formula to:


Good Luck


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nasriramAuthor Commented:
I'd have taken forever to work out that formula... thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.