HLOOKUP easy, but wrong if no exact match?

boznian

Board Regular
Joined
Mar 25, 2003
Messages
161
Actually 2 issues, but here is the most pressing:

=HLOOKUP(E3,$AV$5:$CC$7,3,TRUE)
...works fine as long as the value spec'd in (E3) exists in the table. If not, then I get some (seemingly) random value, which is unacceptable.

So I tried this:
=IF(H3,(HLOOKUP(E3,$AV$5:$CC$7,3,TRUE)),"")

...works fine in my test sheet but I get #VALUE! in my live project?? The "IF(H3" is referring to a text value cell (not the result of any formula).

So A) any thoughts on the #VALUE! error
and B) is there a better (preferred) way to do this rather than HLOOKUP

thankssssss
 

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Do you only want to match against an exact match? If so, then you should be using FALSE as the fourth argument to the Hlookup:

=HLOOKUP(E3,$AV$5:$CC$7,3,FALSE)

If no match is found, this returns #N/A. If you want to return an empty string instead then in xl2007 or above:

=IFERROR(HLOOKUP(E3,$AV$5:$CC$7,3,FALSE),"")

if 2003 or below:

=IF(ISNA(HLOOKUP(E3,$AV$5:$CC$7,3,FALSE)),"",HLOOKUP(E3,$AV$5:$CC$7,3,FALSE))
 

prabby25101981

Active Member
Joined
Jul 28, 2010
Messages
348
You should use "TRUE" as range_lookup (last bit of the hlookup) only if the table where you are trying to find a value is sorted. This is the only way HLOOKUP will produce right results.

Have you tried sorting the table and then use HLOOKUP?
 

boznian

Board Regular
Joined
Mar 25, 2003
Messages
161
"if 2003 or below:

=IF(ISNA(HLOOKUP(E3,$AV$5:$CC$7,3,FALSE)),"",HLOOKUP(E3,$AV$5:$CC$7,3,FALSE))
"
.. OK, that works great! Seems complicated for what I thought should be pretty easy. Never heard of ISNA or any of the other 8 "IS" functions until now! Learning, learning...

"Have you tried sorting the table and then use HLOOKUP? " - yes, the table was already sorted.

Thanks a bunch!
 

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,192
"if 2003 or below:

=IF(ISNA(HLOOKUP(E3,$AV$5:$CC$7,3,FALSE)),"",HLOOKUP(E3,$AV$5:$CC$7,3,FALSE))
"
.. OK, that works great! Seems complicated for what I thought should be pretty easy. Never heard of ISNA or any of the other 8 "IS" functions until now! Learning, learning...

"Have you tried sorting the table and then use HLOOKUP? " - yes, the table was already sorted.

Thanks a bunch!
If AV5:CC5 is in asccending order and can be kept that way, try...

=IF(HLOOKUP(E3,$AV$5:$CC$7,1,1)=E3,HLOOKUP(E3,$AV$5:$CC$7,3,1),"Not Found")

Note. TRUE is also 1 in Excel.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,526
Messages
5,511,830
Members
408,864
Latest member
cmajewsk

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top