Return value based on column header

The Power Loon

New Member
Joined
Feb 7, 2020
Messages
34
Office Version
  1. 365
Platform
  1. Windows
I have a list of values in Table column B with each value corresponding to one of the headers in the table (I attached a sample of the file below). What I'm looking for is a formula or macro that will take the value in column B, determine the corresponding value in the column with the header of the same name, and return it in Column C.

In the sample table below, C2 should be -1.26%. This is because value in B2 is "1005", and the value in row 2 of column 1005 is "-1.26%".

ProductTimeValue95095510001005101010151020
AAA1005-11.41%-2.45%0.00%-1.26%-2.55%1.31%1.94%
BBB95511.28%3.48%2.34%-0.29%1.86%-5.34%-5.20%
CCC1020-3.09%-3.72%-1.10%-4.47%-1.75%0.00%-1.19%
DDD1010-6.11%11.24%-1.60%-1.08%6.56%-2.05%2.09%

I would do a nested IF, but the full sheet has well over 100 columns, making that somewhat unfeasible. Anyone know a method by which to do this?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi, something like this maybe..

Book2
ABCDEFGHIJ
1ProductTimeValue95095510001005101010151020
2AAA1005-1.26%-11.41%-2.45%0.00%-1.26%-2.55%1.31%1.94%
3BBB9553.48%11.28%3.48%2.34%-0.29%1.86%-5.34%-5.20%
4CCC1020-1.19%-3.09%-3.72%-1.10%-4.47%-1.75%0.00%-1.19%
5DDD10106.56%-6.11%11.24%-1.60%-1.08%6.56%-2.05%2.09%
Sheet1
Cell Formulas
RangeFormula
C2:C5C2=XLOOKUP(B2,$D$1:$J$1,D2:J2,"NOT FOUND!")
 
Upvote 0
How about
Fluff.xlsm
ABCDEFGHIJ
1ProductTimeValue95095510001005101010151020
2AAA1005-1.26%-11.41%-2.45%0.00%-1.26%-2.55%1.31%1.94%
3BBB9553.48%11.28%3.48%2.34%-0.29%1.86%-5.34%-5.20%
4CCC1020-1.19%-3.09%-3.72%-1.10%-4.47%-1.75%0.00%-1.19%
5DDD10106.56%-6.11%11.24%-1.60%-1.08%6.56%-2.05%2.09%
Data
Cell Formulas
RangeFormula
C2:C5C2=SUMIFS(D2:J2,$D$1:$J$1,B2)
 
Upvote 0
Solution
Hi, something like this maybe..

Book2
ABCDEFGHIJ
1ProductTimeValue95095510001005101010151020
2AAA1005-1.26%-11.41%-2.45%0.00%-1.26%-2.55%1.31%1.94%
3BBB9553.48%11.28%3.48%2.34%-0.29%1.86%-5.34%-5.20%
4CCC1020-1.19%-3.09%-3.72%-1.10%-4.47%-1.75%0.00%-1.19%
5DDD10106.56%-6.11%11.24%-1.60%-1.08%6.56%-2.05%2.09%
Sheet1
Cell Formulas
RangeFormula
C2:C5C2=XLOOKUP(B2,$D$1:$J$1,D2:J2,"NOT FOUND!")
For whatever reason, it only returns "Not Found" when I tried it, even on the sample. However, no worries. The formula that Fluff sent worked out for me.
Thank you for your time and consideration of this issue.
 
Upvote 0
How about
Fluff.xlsm
ABCDEFGHIJ
1ProductTimeValue95095510001005101010151020
2AAA1005-1.26%-11.41%-2.45%0.00%-1.26%-2.55%1.31%1.94%
3BBB9553.48%11.28%3.48%2.34%-0.29%1.86%-5.34%-5.20%
4CCC1020-1.19%-3.09%-3.72%-1.10%-4.47%-1.75%0.00%-1.19%
5DDD10106.56%-6.11%11.24%-1.60%-1.08%6.56%-2.05%2.09%
Data
Cell Formulas
RangeFormula
C2:C5C2=SUMIFS(D2:J2,$D$1:$J$1,B2)
This worked perfectly, thank you for your response to this question.
 
Upvote 0
For whatever reason, it only returns "Not Found" when I tried it, even on the sample
It's possible that the headers are text and the column B values are numbers (SUMIFS() is less sensitive to that) - you could try one of these alternatives.

=XLOOKUP(""&B2,$D$1:$J$1,D2:J2,"NOT FOUND!")
or
=XLOOKUP(0+B2,$D$1:$J$1,D2:J2,"NOT FOUND!")

I'd suspect that the XLOOKUP() option would give better performance, especially as..
the full sheet has well over 100 columns
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
It's possible that the headers are text and the column B values are numbers (SUMIFS() is less sensitive to that) - you could try one of these alternatives.

=XLOOKUP(""&B2,$D$1:$J$1,D2:J2,"NOT FOUND!")
or
=XLOOKUP(0+B2,$D$1:$J$1,D2:J2,"NOT FOUND!")

I'd suspect that the XLOOKUP() option would give better performance, especially as..
=XLOOKUP(""&B2,$D$1:$J$1,D2:J2,"NOT FOUND!")

This one worked perfectly as well. Thank you for pursuing this.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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