If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > VLOOKUP Formula to return 0 instead of #N/A

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-11-09, 09:21
waylander waylander is offline
Registered User
 
Join Date: Apr 2006
Posts: 52
VLOOKUP Formula to return 0 instead of #N/A

Hi,
the following formula =VLOOKUP(B16,'Number of Accruals'!A2:F1014,6,FALSE)
returns '#N/A' when the lookup value does not exist, i would like to be able to return a '0' in this case.

can anyone please advise on how to do this?

thanks in advance!
Reply With Quote
  #2 (permalink)  
Old 05-11-09, 15:29
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 495
Hi waylander,

If you are using Excel 2007 you can use this:
Code:
=IFERROR(VLOOKUP(B16,'Number of Accruals'!A2:F1014,6,FALSE),)
If you are using an earlier version than Excel 2007 you can use this:
Code:
=IF(ISNA(MATCH(B16,'Number of Accruals'!A2:A1014,0)),,VLOOKUP(B16,'Number of Accruals'!A2:F1014,6,FALSE))
Hope that helps..
Reply With Quote
  #3 (permalink)  
Old 05-12-09, 06:35
waylander waylander is offline
Registered User
 
Join Date: Apr 2006
Posts: 52
Hi Colin,
the second code returns a '0' even if there is a value in the range?
Reply With Quote
  #4 (permalink)  
Old 05-12-09, 07:42
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
Hi

I think this

Code:
=IF(ISERROR(VLOOKUP(B16,'Number of Accruals'!A2:F1014,6,FALSE)),,VLOOKUP(B16,'Number of Accruals'!A2:F1014,6,FALSE))
or this
Code:
=IF(ISNA(VLOOKUP(B16,'Number of Accruals'!A3:F1015,6,FALSE)),,VLOOKUP(B17,'Number of Accruals'!A3:F1015,6,FALSE))
Should do it ??

MTB
Reply With Quote
  #5 (permalink)  
Old 05-12-09, 08:40
waylander waylander is offline
Registered User
 
Join Date: Apr 2006
Posts: 52
Colin,
i do beg your pardon your second formula works well, i realised that i hadn't referenced the cells correctly many thanks,
Mike your formula works well too,
many thanks guys!!!
Reply With Quote
  #6 (permalink)  
Old 05-12-09, 15:04
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 495
Quote:
Originally Posted by waylander
Colin,
i do beg your pardon your second formula works well, i realised that i hadn't referenced the cells correctly many thanks,
No worries, glad you got it working.
Reply With Quote
  #7 (permalink)  
Old 10-26-09, 21:35
pete.ford pete.ford is offline
Registered User
 
Join Date: Oct 2009
Posts: 3
help

I am very new to excel, (2 days) and stumbled across this thread.
I am stumbling my way through Excel trying to make a calculation sheet using referenced matricies in attached workbooks to calculate a score based on time, and a few other factors.

My main problem is very close to what you have already solved, and I can't seem to get the syntax right.

I need to return a "0" if none of the conditions exist.

here is my line of code (i'm sure there is a better way to do it, but it is working, be gentle...lol)

=IF((AND(G45="TRPS",BC1="STA")),VLOOKUP(AW45,troop sdefense!A1:V51,Sheet1!M45/100),IF((AND(G45="TRPS",BC1="MOV")),VLOOKUP(AW45,t roopsoffense!A1:V51,Sheet1!M45/100),IF((AND(G45="TRK",BC1="STA")),VLOOKUP(AW45,tr uckdefense!A1:V51,Sheet1!M45/100),IF((AND(G45="TRK",BC1="MOV")),VLOOKUP(AW45,tr uckoffense!A1:V51,Sheet1!M45/100),IF((AND(G45="PC",BC1="STA")),VLOOKUP(AW45,pcd efense!A1:V51,Sheet1!M45/100),IF((AND(G45="PC",BC1="MOV")),VLOOKUP(AW45,pco ffense!A1:V51,Sheet1!M45/100)))))))

I just need it to return a value of "0" if none of these conditions exist
Reply With Quote
  #8 (permalink)  
Old 10-27-09, 01:25
AnanthaP AnanthaP is offline
Registered User
 
Join Date: May 2009
Location: India
Posts: 62
Hi pete.ford,

Without going deeply into the statement, all you should probably do is to remember your spec which says I need to return a "0" if none of the conditions exist. ie if the final result is '#N/A' . If this is so, then it might be sufficient to enclose the entire script in one if(iserror(...)
Reply With Quote
  #9 (permalink)  
Old 10-27-09, 04:04
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
Quote:
Originally Posted by pete.ford
I am very new to excel, (2 days) and stumbled across this thread.
I am stumbling my way through Excel trying to make a calculation sheet using referenced matricies in attached workbooks to calculate a score based on time, and a few other factors.

My main problem is very close to what you have already solved, and I can't seem to get the syntax right.

I need to return a "0" if none of the conditions exist.

here is my line of code (i'm sure there is a better way to do it, but it is working, be gentle...lol)

=IF((AND(G45="TRPS",BC1="STA")),VLOOKUP(AW45,troop sdefense!A1:V51,Sheet1!M45/100),IF((AND(G45="TRPS",BC1="MOV")),VLOOKUP(AW45,t roopsoffense!A1:V51,Sheet1!M45/100),IF((AND(G45="TRK",BC1="STA")),VLOOKUP(AW45,tr uckdefense!A1:V51,Sheet1!M45/100),IF((AND(G45="TRK",BC1="MOV")),VLOOKUP(AW45,tr uckoffense!A1:V51,Sheet1!M45/100),IF((AND(G45="PC",BC1="STA")),VLOOKUP(AW45,pcd efense!A1:V51,Sheet1!M45/100),IF((AND(G45="PC",BC1="MOV")),VLOOKUP(AW45,pco ffense!A1:V51,Sheet1!M45/100)))))))

I just need it to return a value of "0" if none of these conditions exist
Hi

Without looking too hard, I think, perhapse, this may do it

=IF((AND(G45="TRPS",BC1="STA")),VLOOKUP(AW45,troop sdefense!A1:V51,Sheet1!M45/100),IF((AND(G45="TRPS",BC1="MOV")),VLOOKUP(AW45,t roopsoffense!A1:V51,Sheet1!M45/100),IF((AND(G45="TRK",BC1="STA")),VLOOKUP(AW45,tr uckdefense!A1:V51,Sheet1!M45/100),IF((AND(G45="TRK",BC1="MOV")),VLOOKUP(AW45,tr uckoffense!A1:V51,Sheet1!M45/100),IF((AND(G45="PC",BC1="STA")),VLOOKUP(AW45,pcd efense!A1:V51,Sheet1!M45/100),IF((AND(G45="PC",BC1="MOV")),VLOOKUP(AW45,pco ffense!A1:V51,Sheet1!M45/100),0))))))

That is, the 'False' condition in the last IF statement is zero (there is no false condition in the last IF in your statement). This last False condition is the one returened if ALL the condition in ALL the IF statements are false !!?

HTH

MTB
Reply With Quote
  #10 (permalink)  
Old 10-27-09, 05:03
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 495
I would add:

[1] Don't try to do too much in one formula: it makes it hard to debug and maintain, and may even make your worksheet calculate more slowly. You have lots of space on a worksheet so don't be afraid to use it by splitting the formula up!
[2] Consider using descriptive named ranges to make your formulas easier to understand and (possibly) shorter.
Reply With Quote
  #11 (permalink)  
Old 10-27-09, 06:23
pete.ford pete.ford is offline
Registered User
 
Join Date: Oct 2009
Posts: 3
Thank you

Mike, that was exactly what I was looking for, I knew it was simple.
Thank you very much.
Reply With Quote
  #12 (permalink)  
Old 10-27-09, 06:37
pete.ford pete.ford is offline
Registered User
 
Join Date: Oct 2009
Posts: 3
Anantha, I will research if(iserror()) , I will probably need that also

Colin, sounds like good advice (problem solving process)

Thank you all for your input, it is greatly appreciated
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On