Vlookup based on certain criteria

Tashat

Board Regular
Joined
Jan 12, 2005
Messages
135
Office Version
  1. 365
Platform
  1. Windows
Hello Everyone

I'm looking for some help with an If statement and vlookup (I think). I would like to use a formula in column B, which looksup using the Role ID in Column A, against the role ID in column D and then returns the name of the employee. However, I have repeated role IDs in column D, because some employees have resigned and a new employee has replaced them and been assigned the same role ID. I can't delete these resigned employees because I need to keep this historical information in the sheet. Is there a way I can use an if statement (or similar) to ignore the role-if if column F shows as resigned? So I only return the name of the current employee in column B?

I use Excel 365. Thank you in advance.


Book1
ABCDEF
1Role_IDEmployee NameRole-IDEmployee NameStatus
2XE-CEC1XE-CEC1AmyCurrent
3XE-CEB1XE-CEB1FredResigned
4XC-CEH1XE-CEB1AnneCurrent
5XL-CEB1XL-CEB1MoCurrent
6XJ-CEB1XJ-CEB1SamCurrent
7XH-CEA1XH-CEA1AlfResigned
8XH-CEK1XH-CEA1SarahCurrent
9XE-CEA1XC-CEK1NaomiCurrent
10XC-CEK1XK-CEB1MattResigned
11XK-CEB1XK-CEB1LucasCurrent
12XH-CED1XH-CED1DanielleResigned
13XJ-CED1XH-CED1JeremyCurrent
14XH-CEJ1XH-CEJ1JohnCurrent
15XH-CEB1XH-CEB1AndreaCurrent
Sheet1
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
How about
+Fluff v2.xlsm
ABCDEF
1Role_IDEmployee NameRole-IDEmployee NameStatus
2XE-CEC1AmyXE-CEC1AmyCurrent
3XE-CEB1AnneXE-CEB1FredResigned
4XC-CEH1 XE-CEB1AnneCurrent
5XL-CEB1MoXL-CEB1MoCurrent
6XJ-CEB1SamXJ-CEB1SamCurrent
7XH-CEA1SarahXH-CEA1AlfResigned
8XH-CEK1 XH-CEA1SarahCurrent
9XE-CEA1 XC-CEK1NaomiCurrent
10XC-CEK1NaomiXK-CEB1MattResigned
11XK-CEB1LucasXK-CEB1LucasCurrent
12XH-CED1JeremyXH-CED1DanielleResigned
13XJ-CED1 XH-CED1JeremyCurrent
14XH-CEJ1JohnXH-CEJ1JohnCurrent
15XH-CEB1AndreaXH-CEB1AndreaCurrent
Master
Cell Formulas
RangeFormula
B2:B15B2=XLOOKUP(A2&"|Current",$D$2:$D$15&"|"&$F$2:$F$15,$E$2:$E$15,"")
 
Upvote 0
How about
+Fluff v2.xlsm
ABCDEF
1Role_IDEmployee NameRole-IDEmployee NameStatus
2XE-CEC1AmyXE-CEC1AmyCurrent
3XE-CEB1AnneXE-CEB1FredResigned
4XC-CEH1 XE-CEB1AnneCurrent
5XL-CEB1MoXL-CEB1MoCurrent
6XJ-CEB1SamXJ-CEB1SamCurrent
7XH-CEA1SarahXH-CEA1AlfResigned
8XH-CEK1 XH-CEA1SarahCurrent
9XE-CEA1 XC-CEK1NaomiCurrent
10XC-CEK1NaomiXK-CEB1MattResigned
11XK-CEB1LucasXK-CEB1LucasCurrent
12XH-CED1JeremyXH-CED1DanielleResigned
13XJ-CED1 XH-CED1JeremyCurrent
14XH-CEJ1JohnXH-CEJ1JohnCurrent
15XH-CEB1AndreaXH-CEB1AndreaCurrent
Master
Cell Formulas
RangeFormula
B2:B15B2=XLOOKUP(A2&"|Current",$D$2:$D$15&"|"&$F$2:$F$15,$E$2:$E$15,"")
Thank you Fluff- as always. Stunning formula! I've never seen a formula which uses | before! I can't even unpick what each part of this formula is doing. Usually I can work out the logic, but not with this one.
 
Upvote 0
The | is just used as a separator to ensure that the correct values are found, although it's not really needed here, I tend to use it any way.

With the data below, if you concatenate the 2values together without a separator all the rows are the same, but with the | then they are still distinct
+Fluff v2.xlsm
HIJK
1
2abcdef11
3abcdef12
4abcdef13
Master
Cell Formulas
RangeFormula
J2:J4J2=MATCH(H2&I2,$H$2:$H$4&$I$2:$I$4,0)
K2:K4K2=MATCH(H2&"|"&I2,$H$2:$H$4&"|"&$I$2:$I$4,0)
 
Upvote 0
The | is just used as a separator to ensure that the correct values are found, although it's not really needed here, I tend to use it any way.

With the data below, if you concatenate the 2values together without a separator all the rows are the same, but with the | then they are still distinct
+Fluff v2.xlsm
HIJK
1
2abcdef11
3abcdef12
4abcdef13
Master
Cell Formulas
RangeFormula
J2:J4J2=MATCH(H2&I2,$H$2:$H$4&$I$2:$I$4,0)
K2:K4K2=MATCH(H2&"|"&I2,$H$2:$H$4&"|"&$I$2:$I$4,0)
Oh yes - I remember using | now many moons ago when I used Lotus 123! Blimey! Thank you.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,397
Members
448,957
Latest member
Hat4Life

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