HLOOKUP and MATCH

Jar888

Board Regular
Joined
Jan 15, 2022
Messages
61
Office Version
  1. 2016
Platform
  1. Windows
Just wondering what's going on, because my formula is giving me two different results depending on where it's located. I'll add some cells and some screen shots. Just not sure why it's working for some cells and not for others. I assumed HLOOKUP as a TRUE position gave me the last match in a row. Please see below.

First where it's wrong;

Cheat Sheet.xlsx
AOAPAQARASAT
88ALALALAL16/06/2022 
89ALALALD16/06/2022 
Roster Dump
Cell Formulas
RangeFormula
AO88:AR89AO88=IFERROR(INDEX('F:\Data\2579\13 Progress Reporting Programming\05 Wkly Rpts\Reference Files\[EMPLOYEE ROSTER.xlsx]ROSTER'!$N$5:$AWG$250,MATCH($A88,'F:\Data\2579\13 Progress Reporting Programming\05 Wkly Rpts\Reference Files\[EMPLOYEE ROSTER.xlsx]ROSTER'!$E$5:$E$250,0),MATCH(AO$2,'F:\Data\2579\13 Progress Reporting Programming\05 Wkly Rpts\Reference Files\[EMPLOYEE ROSTER.xlsx]ROSTER'!$3:$3,0)),"")
AS88:AS89AS88=IFERROR(IF(B88="","",INDEX($C$2:$AR$2,MATCH(HLOOKUP("AL",C88:AR88,1,FALSE),C88:AR88,0))),"")
AT88:AT89AT88=IFERROR(IF(B88="","",INDEX($C$2:$AR$2,MATCH(HLOOKUP("AL",C88:AR88,1,TRUE),C88:AR88))),"")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1:AR300Expression=A1="AL"textNO


1652232410156.png


As you can see, it's not picking up the last date for whatever reason. But later down the sheet I get;

1652232482249.png


From;

Cheat Sheet.xlsx
ASAT
14213/05/202218/05/2022
1432/06/20222/06/2022
Roster Dump
Cell Formulas
RangeFormula
AS142:AS143AS142=IFERROR(IF(B142="","",INDEX($C$2:$AR$2,MATCH(HLOOKUP("AL",C142:AR142,1,FALSE),C142:AR142,0))),"")
AT142:AT143AT142=IFERROR(IF(B142="","",INDEX($C$2:$AR$2,MATCH(HLOOKUP("AL",C142:AR142,1,TRUE),C142:AR142))),"")
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
HLOOKUP works the same as VLOOKUP, it gives you the first occurence.
Try LOOKUP
Book1
ALAMANAOAP
8716/06/202217/06/202218/06/202219/06/2022
88ALALALAL19/06/2022
89ALALALD18/06/2022
Sheet1
Cell Formulas
RangeFormula
AP88:AP89AP88=LOOKUP("AL",$AL88:$AO88,$AL$87:$AO$87)
 
Upvote 0
I just get #N/A error when I try that?

Cheat Sheet.xlsx
AU
88#N/A
Roster Dump
Cell Formulas
RangeFormula
AU88AU88=LOOKUP("AL",$C88:$AR88,$C$2:$AR$2)
 
Upvote 0
Edit: Ah, I see that while composing my post one of the issues mentioned may have arisen for the OP.

Try LOOKUP
Just a slight word of warning if using LOOKUP - some strange results may arise if "AL" does not occur in the row. See highlighted cells below - especially AP91
Could be modified as in column AQ or an alternative in column AR

22 05 11.xlsm
ALAMANAOAPAQAR
8716/06/202217/06/202218/06/202219/06/2022
88ALALALAL19/06/202219/06/202219/06/2022
89DALALD18/06/202218/06/202218/06/2022
90D#N/A  
91ABABAB18/06/2022  
LOOKUP
Cell Formulas
RangeFormula
AP88:AP91AP88=LOOKUP("AL",$AL88:$AO88,$AL$87:$AO$87)
AQ88:AQ91AQ88=IF(COUNTIF(AL88:AO88,"AL"),LOOKUP("AL",$AL88:$AO88,$AL$87:$AO$87),"")
AR88:AR91AR88=IFERROR(AGGREGATE(14,6,AL$87:AO$87/(AL88:AO88="AL"),1),"")
 
Upvote 0
Solution
I'll have a look at the aggregate solution.

I thought about using countif, but the problem arises when AL is split across a break. Example below;

1652237614053.png
 
Upvote 0
Aggregate works pretty good. I've tested it on a few different extracts.

See below CountIF function;

1652238188727.png


Cheat Sheet.xlsx
ANAOAPAQARASAT
22AL AL 15/06/2022#N/A
Roster Dump
Cell Formulas
RangeFormula
AP22,AR22AP22=IFERROR(INDEX('[EMPLOYEE ROSTER.xlsx]ROSTER'!$N$5:$AWG$250,MATCH($A22,'[EMPLOYEE ROSTER.xlsx]ROSTER'!$E$5:$E$250,0),MATCH(AP$2,'[EMPLOYEE ROSTER.xlsx]ROSTER'!$3:$3,0)),"")
AS22AS22=IFERROR(IF(B22="","",INDEX($C$2:$AR$2,MATCH(HLOOKUP("AL",C22:AR22,1,FALSE),C22:AR22,0))),"")
AT22AT22=IF(COUNTIF(AL22:AR22,"AL"),LOOKUP("AL",AL2:AR2,AL22:AR22),"")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1:AR300Expression=A1="AL"textNO
 
Upvote 0

Forum statistics

Threads
1,223,981
Messages
6,175,768
Members
452,668
Latest member
mrider123

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