Rank: Master
Rating: 93%, 28 votes
The problem doesn't say this explicitly, but it looks like you're using Excel. This answer depends on that assumption being correct.
Are you saying that some of your inputs are blank? And LOOKUP fails to map them to 0? Or are you saying that some of your values come back from LOOKUP as blanks? (They shouldn't; lookup should return either a value from the lookup table or an error.) Or is it the case that some input values get mapped to blank by your LOOKUP function?
Assuming that you're getting blanks back from LOOKUP where you wanted zeros -- for whatever reason -- here is something you can try.
It looks like the value you're looking up is in cell A3. Let's say your formula (the result of the LOOKUP) is in B3. In C3, you can put the formula =IF(ISBLANK(A3), 0, A3). This function tests if A3 is blank. If it is, it returns a 0. If it's not, you get A3 again. (But A3 has to really be blank -- spaces will count as non-blank.)
Then, you can copy data out of column C instead of column B, and it should have zeros in place of blanks.
Comments:
Jan 06, 2008
- LOOKUP returns #N/A when the value you're looking up is less than the smallest number in the lookup table. You can detect this after the fact using the ISERROR function.
Thus, you can follow the advice in the solution above, except use the formula =IF(ISERROR(A3), 0, A3). This will have your original results in column A and your new results in a new column. I like doing it this way, because it's easy to test and make sure everything's working right.
Once you're satisfied that the formulas are working properly, you can combine both formulas into one. Change your formula from this:
=LOOKUP(A3,'DCT INFO'!A:A,'DCT INFO'!B:B)
to this:
=ISERROR(LOOKUP(A3,'DCT INFO'!A:A,'DCT INFO'!B:B),0,LOOKUP(A3,'DCT INFO'!A:A,'DCT INFO'!B:B))
This formula is saying, do the lookup. If it is an error, put 0 in the cell. Otherwise, put the lookup value in the cell.