Find match of row header using a lookup

pabybhoy

New Member
Joined
Jul 19, 2013
Messages
16
Hi,

This may be diffult to explain so apologies in advance.
I'm creating a summary sheet which uses another file to lookup the salary and department using the surname. I can get the salary ok using vlookup but im having trouble getting the department due to the format of the sheet.
I need it to find the name (Col B) then move one cell right, search up to find next non blank cell then give me the cell value above that one.

Is this possible in a formula or even vba?
Unfortunately I can't change the format of this sheet as it come direct from the system, and it needs to be dynamic as the number of employees could change.
I've attached an example of lookup sheet.
Thanks
 

Attachments

  • example.PNG
    example.PNG
    9.9 KB · Views: 7

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Looks like Power Query (or "Get & Transform" as they call it nowadays) would be your best friend here. It was first introduced as a free Excel addin in 2013 and has been found under the Data tab of the ribbon since Excel 2016.

You'll find great Power Query tutorials in YouTube. What you basically need is the "Fill down" option but you might as well want to get rid of the total rows & extra headers as well.
 
Upvote 0
or try this to see if it works for you

cells H2 and I2 make it easier to follow how the formula works

Do the whole thing in one formula using formula in J2
=INDEX(OFFSET(C1,0,0,MATCH(G2,B:B,0)),MAX((OFFSET(C1,0,0,MATCH(G2,B:B,0))<>"")*(ROW(OFFSET(C1,0,0,MATCH(G2,B:B,0))))))


Book1
ABCDEFGHIJK
1Department No. /NameApples-NameMatch rowDeptIn one
2EmpRefEmployee NameSalaryShona11OrangesOranges
3Peter2503
4John2504
5Mary2505
6Department No. /NameOranges-
7EmpRefEmployee NameSalary
8Harry2508
9Jenny2509
10Naomi2510
11Shona2511
12Department No. /NamePears-
13EmpRefEmployee NameSalary
14Graham2514
15Brian2515
16Lorna2516
17Charles2517
18
Sheet1
Cell Formulas
RangeFormula
H2H2=MATCH(G2,B:B,0)
I2I2=INDEX(OFFSET(C1,0,0,H2),MAX((OFFSET(C1,0,0,H2)<>"")*(ROW(OFFSET(C1,0,0,H2)))))
J2J2=INDEX(OFFSET(C1,0,0,MATCH(G2,B:B,0)),MAX((OFFSET(C1,0,0,MATCH(G2,B:B,0))<>"")*(ROW(OFFSET(C1,0,0,MATCH(G2,B:B,0))))))
 
Upvote 0
or try this to see if it works for you

cells H2 and I2 make it easier to follow how the formula works

Do the whole thing in one formula using formula in J2
=INDEX(OFFSET(C1,0,0,MATCH(G2,B:B,0)),MAX((OFFSET(C1,0,0,MATCH(G2,B:B,0))<>"")*(ROW(OFFSET(C1,0,0,MATCH(G2,B:B,0))))))


Book1
ABCDEFGHIJK
1Department No. /NameApples-NameMatch rowDeptIn one
2EmpRefEmployee NameSalaryShona11OrangesOranges
3Peter2503
4John2504
5Mary2505
6Department No. /NameOranges-
7EmpRefEmployee NameSalary
8Harry2508
9Jenny2509
10Naomi2510
11Shona2511
12Department No. /NamePears-
13EmpRefEmployee NameSalary
14Graham2514
15Brian2515
16Lorna2516
17Charles2517
18
Sheet1
Cell Formulas
RangeFormula
H2H2=MATCH(G2,B:B,0)
I2I2=INDEX(OFFSET(C1,0,0,H2),MAX((OFFSET(C1,0,0,H2)<>"")*(ROW(OFFSET(C1,0,0,H2)))))
J2J2=INDEX(OFFSET(C1,0,0,MATCH(G2,B:B,0)),MAX((OFFSET(C1,0,0,MATCH(G2,B:B,0))<>"")*(ROW(OFFSET(C1,0,0,MATCH(G2,B:B,0))))))

Hi,

Thanks for the reply. I've tested this formula and I'm getting the top line every time. Its getting the Match Row but formulas in col I & J both give "Apples"


Book33
ABCDEFGHIJ
1Department No. / Name :Apples-NameMatch RowDeptIn one
2Emp RefEmployee NamesalaryCross11ApplesApples
3Smith2500.00
4Jones2501.00
5Parker2502.00
6Johnson2503.00
7Department No. / Name :Oranges-
8Emp RefEmployee Namesalary
9Baker2504.00
10Martin2501.00
11Cross2502.00
12Dept. Total :7507.00
13Department No. / Name :Pears-
14Emp RefEmployee Namesalary
15Ferguson2500.00
16Dept. Total :2500.00
17
Sheet1
Cell Formulas
RangeFormula
H2H2=MATCH(G2,B:B,0)
I2I2=INDEX(OFFSET(C1,0,0,H2),MAX((OFFSET(C1,0,0,H2)<>"")*(ROW(OFFSET(C1,0,0,H2)))))
J2J2=INDEX(OFFSET(C1,0,0,MATCH(G2,B:B,0)),MAX((OFFSET(C1,0,0,MATCH(G2,B:B,0))<>"")*(ROW(OFFSET(C1,0,0,MATCH(G2,B:B,0))))))
 
Upvote 0
Ignore the above. I hadn't used the Control Shift to enter the formula.
I had to tweak slightly as the word salary is underneath the dept name but got it working now.
Thank you so much for all your help
 
Upvote 0
How strange that it works for me, but not for you
- everything looks identical

Something you could try which also works for me
- edit cell J2 and (instead of the usual ENTER ) confirm the formula with {CRTRL}{SHIFT}{ENTER}
- which converts the formula to an array formula and places { } around the formula (which does not work if you do it manually
- same for cell I2

Array.jpg
 
Upvote 0
It may be an Excel 365 change - perhaps 365 recognises an array formula without being told explicitly :unsure:
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,431
Members
448,961
Latest member
nzskater

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