Solved

where #N/A return 0

Posted on 2014-11-28
8
168 Views
Last Modified: 2014-12-01
Collumns E & F have a number of cells that have returned N/A.

Can someone help me with a formula to return a "0" to replace all the N/A's

Rob
Copy-of-cost-prices.xlsx
0
Comment
Question by:robmarr700
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 18

Assisted Solution

by:Simon
Simon earned 84 total points
ID: 40470536
The first thing I see is a circular reference warning!

But apart from that, it's your vlookup that are causing the error becuase that function returns an error if it doesn't find a match:
=VLOOKUP(A175,'P:\THS Direct Admin\Reports\[THS DIRECT (sales master).xlsm]Product Sales'!$A:$P,16,FALSE)
If you wrap the vlookup function with the iferror function you'll avoid them

e.g. =IFERROR(=VLOOKUP(A175,'P:\THS Direct Admin\Reports\[THS DIRECT (sales master).xlsm]Product Sales'!$A:$P,16,FALSE),0)
0
 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 83 total points
ID: 40470548
Of course the equal sign inside of IFERROR is a typo:
=IFERROR(VLOOKUP(A175,'P:\THS Direct Admin\Reports\[THS DIRECT (sales master).xlsm]Product Sales'!$A:$P,16,FALSE),0)
0
 
LVL 18

Expert Comment

by:Simon
ID: 40470595
Of course :) Well spotted. You deserve that halo!
0
 
LVL 81

Assisted Solution

by:byundt
byundt earned 166 total points
ID: 40471605
Searching a closed workbook is going to take a fair amount of time. Searching entire columns for information that isn't there will take much more time. My tests on a closed file stored on a SSD in my laptop suggest about 2 seconds per cell if you search an entire column of a closed workbook for information that isn't there. Restricting the range makes it noticeably faster.

Opening the target workbook before opening the workbook with the formula would be best. If that is not possible, I suggest that you restrict the range being searched to the actual range of data, or to a range that doesn't extend much beyond it. For example:
=IFERROR(VLOOKUP(A175,'P:\THS Direct Admin\Reports\[THS DIRECT (sales master).xlsm]Product Sales'!$A$1:$P$10000,16,FALSE),0)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 23

Assisted Solution

by:Danny Child
Danny Child earned 83 total points
ID: 40471613
I think you actually want to use the **result** of the vlookup in the other cells, so it's not enough to just return the zero if it fails.  If that's right, you might want to consider this - in Cell E2, to fill down...

=IF(ISNA(MATCH(A2,'P:\THS Direct Admin\Reports\[THS DIRECT (sales master).xlsm]Product Sales'!$A:$A,0)),0,VLOOKUP(A2,,'P:\THS Direct Admin\Reports\[THS DIRECT (sales master).xlsm]Product Sales'!$A:$P,16,FALSE))

I also used ISNA instead of ISERROR to be more specific about the error code trapping that you want.  

Also, if you're just checking that a value exists, it makes more sense to use a MATCH first, and then do the VLOOKUP only if needed.
0
 
LVL 81

Accepted Solution

by:
byundt earned 166 total points
ID: 40472119
I think you actually want to use the **result** of the vlookup in the other cells, so it's not enough to just return the zero if it fails.
I'm not following the above assertion. While ISNA does allow you to be more specific in error trapping, the IFERROR statement returns either the result of the VLOOKUP or a 0. And the real benefit of the IFERROR is that you don't have to perform a time-consuming search on a closed workbook twice if no error occurs.

MATCH and VLOOKUP are about the same speed. The real benefit of using MATCH occurs when you want to return more than one column of information. You can then store the result of the MATCH in an auxiliary column and use an INDEX formula with the result of the MATCH to return the desired values. This will be much faster than using a VLOOKUP for each column of desired information because the INDEX formulas know exactly which row to go to.

If speed is a real concern, then you would also want to sort the closed workbook by its column A. You could then use the binary search form of MATCH (or VLOOKUP) to return values. The binary search will be an order of magnitude (or more) faster in returning information.
=IF(IFERROR(VLOOKUP(A2,'P:\THS Direct Admin\Reports\[THS DIRECT (sales master).xlsm]Product Sales'!$A:$A,1,TRUE),"")<>A2,"",MATCH(A2,'P:\THS Direct Admin\Reports\[THS DIRECT (sales master).xlsm]Product Sales'!$A:$A,1))
=IF($B2="",0,INDEX('P:\THS Direct Admin\Reports\[THS DIRECT (sales master).xlsm]Product Sales'!P:P,$B2))

The first formula above requires closed workbook column A to be sorted in ascending order. It then uses the binary form of VLOOKUP to test if an exact match is found. If so, it uses the binary form of MATCH to return the index (row) number. If not, an empty string (looks like a blank) is returned.

The second formula above tests whether the index number in cell B2 is an empty string. If so, the formula returns 0 (or an empty string if you prefer). If an index number exists in cell B2, then the INDEX function returns the desired value. I put a $ in front of B2 to fix the reference to the MATCH column while you copy the formula across to get data from column P, then Q, R, S, T, etc.
0
 
LVL 5

Assisted Solution

by:Hakan Yılmaz
Hakan Yılmaz earned 84 total points
ID: 40472190
You have a basic circular reference in cell F2, it seeks for its own value to calculate its own value.

You may change your F column formula to IFERROR(D2*E2,0). Even if the value you seek in another file doesnt exists, calculation with this formula will hide it as zero.
0
 
LVL 23

Expert Comment

by:Danny Child
ID: 40474412
Having double-checked, the points that Qlemo and Byundt make are, of course, correct.  I thought it was pretty unlikely that they'd have made a mistake, but I ploughed on regardless... sorry, guys!

My solution works, it's just not as elegant.  I was also wrong about some of the subtleties of the IFERROR function.  

Comparing the speed of VLOOKUP to INDEX/MATCH (and not just MATCH) showed a slight speed improvement for the latter here:
http://exceluser.com/blog/727/excels-fastest-lookup-methods-the-tested-results.html
but of course we're surmising here about a) the amount of data being checked (even though whole rows are mentioned, they could be largely blank), and b) whether that sheet is actually closed when it's being recalculated.  

I think the circular ref problems are just due to this sheet being a Work In Progress.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now