Solved

IF Statement in Excel returns 0, instead of nothing

Posted on 2011-03-21
4
173 Views
Last Modified: 2012-05-11
I have this value in my excel worksheet:
=IF((ISNUMBER(FIND("BD",'Sheet1'!$C34))),'Sheet1'!Y34,"")

If Excel finds "BD", I get the value in "Sheet1, cell Y34".  (Works gret)  

If it doesn't find "Fred" I get a 0. (Not what I want)

What I would like it to do is return a blank value, or no value - otherwise I get zeros all over the place - and 1/0/1900 for any date columns.

Is there a better way to check to see if a column contains a string of letters?  In my case, I have a sheet filled with values where some start with BD or AD but have different numbers after that.  I need to be able to grab just the cells that have a "BD"

I hope that makes sense...

0
Comment
Question by:slightlyoff
4 Comments
 
LVL 50

Expert Comment

by:Dave Brett
Comment Utility
>Is there a better way to check to see if a column contains a string of letters?

Regardless of your test, you need to return a negative result then you then need to clean up

One way - without code - would be to introduce a deliberate error than can be wiped out quickly

1)  use a formula like this =IF((ISNUMBER(FIND("BD",'Sheet1'!$C34))),'Sheet1'!Y34,NA())
to return NA() rather than"" for no match
2) select your area of formlae
3) Press F5   .... Special
4) Then check "Errors" under "Formulas"
5) This selects only the NA() cells (ie the non strings), which you can delete win a single shot

Cheers

Dave
0
 
LVL 24

Expert Comment

by:jimyX
Comment Utility
Find (or Search) are the best to check the strings for sub-string.

You need to use ISERROR instead:
=IF((ISERROR(FIND("BD",'Sheet1'!$C34))),"",'Sheet1'!Y34)
0
 
LVL 50

Accepted Solution

by:
barry houdini earned 500 total points
Comment Utility
If you get a zero with that formula that's in fact because BD is found but Y34 is blank.

Try changing to this version which will also allow zero when that's a valid return

=IF(ISNUMBER(FIND("BD",'Sheet1'!$C34)),IF('Sheet1'!Y34="","",'Sheet1'!Y34),"")

regards, barry
0
 
LVL 1

Author Closing Comment

by:slightlyoff
Comment Utility
Thank you.  This produced exactly what I was looking for.

The other 2 solutions acutally produced the same thing I had, but I may have done something incorrectly.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

743 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

11 Experts available now in Live!

Get 1:1 Help Now