Welcome to Excel Magic Trick number 1,155. If you want to download this workbook and follow along, click on the link below the video. In this video, we want to talk about using the IF function to check whether a cell is empty. I put this in edit mode, and there's no space, zero-length text string, or anything there. There's just nothing there. But we also want to distinguish, because sometimes formulas will use double quotes, double quotes, which is actually text but shows nothing. Technically, it's called a zero-length text string. This is a common result from formulas, so sometimes even though when I hit Enter it looks empty, it's not.
Now we want to build a logical test to see whether there's something in the cell or not. In this column, all I want to see is when there's a date over here, I want to show the word Yes. So I'm going to say equals IF, and the first way we're going to do the logical test is: hey, relative cell reference, are you equal to double quotes, double quotes? This will find both the empty cell and the zero-length text string. So if it is empty, comma, the value of true: I want to show nothing, double quotes, double quotes. Otherwise, the value of false, which means there is something there, I want to put in double quotes, Yes, in double quotes. Notice these are both text. If we were counting them with the LEN function for the length, this would be zero, and this would be three. Close parentheses, Control+Enter, double-click, and send it down.
Now let's see if we can look for just the empty cell. The way you do that is equals IF, and you use IS BLANK. Here's a big problem with terminology in Excel: people call this cell blank, and they call this cell blank too, but really this is an empty cell, and this is a zero-length text string. So the word blank is kind of ambiguous in Excel. But if you look at help, IS BLANK finds an empty cell. So really this should be "is empty cell." If that's true, which means it's an empty cell, then I want to show double quotes, double quotes. Otherwise, I'd like to show Yes.
The funny thing is, here we are dumping this zero-length text string into the cell. I don't know of a way to actually dump an empty cell, or nothing, or a null value, into the cell. If you're starting to learn Power Pivot, I've been using it for a long time. Over in Power Pivot there's a BLANK function, and that BLANK function is neither a zero-length text string nor an empty cell. It's actually considered a null. But over here in Excel we're stuck with this double quotes, double quotes, which is Control+Enter, a zero-length text string.
Now, this one here, because we used IS BLANK, will only find the empty cell. This is just illustrating that we do have a way to just check for an empty cell. Actually, for this particular example we could right-click, Insert, and check for a number, if you wanted to see different ways. We could use IS NUMBER, because dates are serial numbers underneath. This switches up the logic: if it is a number, then for the value of true we want Yes; otherwise, value of false, which means it's something besides a number, double quotes, double quotes, close parentheses. That's not really what we're trying to illustrate here. We're trying to figure out the difference between checking for an empty cell and checking for a blank. But this is to remind you that yes, we could check for the date, and we'd get the same pattern as the first one, because this is empty and this is text. Neither of them is a number.
Now let's go over here. Notice there's a little key down here: yellow is empty cell, and the lighter yellow is zero-length text. Let's come over here and make a formula for two dates. We're checking two cells, because if we were just checking one cell we'd miss these over here. So here I'm going to go IF, and we're going to use the OR function. I'm going to say: hey, are you cell reference to two to my left, are you equal to double quotes? The second logical test is the one cell to my left: are you equal to double quotes, double quotes? Close parentheses. That's OR. This will deliver true if it finds one here, if it finds one here, or if it finds one in both. Remember, double quotes, double quotes searches for both zero-length text strings and empty cells. Comma, if that's true, I'm going to show double quotes, double quotes. Otherwise, I'm going to run a formula, which is the end date minus the earlier date, close parentheses, Control+Enter, double-click, and send it down. Here we're calculating the number of days between two dates, but when we don't have one of the values, or both of the values, we want to show nothing.
This one's fine. It checks for that double quotes, double quotes. But we could think of dates as numbers, because they are numbers, and in that case we could go IF and use the COUNT function. In this case I like this because I can count both of these numbers, relative cell references, and when there are two values, the count gives me two. I'm checking for less than two, which would give me a count of one, because only one number is there. COUNT sees empty cells and zero-length text as neither being numbers, so it counts neither of them. So I'm going to say less than two. If that's true, less than two, then I want to show double quotes, double quotes. Otherwise I want to run the formula, end minus start, close parentheses, Control+Enter, double-click, and send it down.
That was a little fun with checking for empty cells. We used COUNT, and we used OR with two logical tests when checking two cells. We showed IS NUMBER if we wanted to check whether something is a number, but really we wanted to look at the difference between BLANK, which only sees empty cells, and zero-length text strings. That checks for either one of them. All right, we'll see you next trick.
