IF() Function Syntax Option

Colin Legg

MrExcel MVP
Joined
Feb 28, 2008
Messages
3,507
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Syntax said:
IF(logical_test, [value_if_true], [value_if_false])



I noted today that in the helpfile topic for the IF() worksheet function it is possible to omit both the function's 2nd and 3rd arguments.

Although to do so you have to add a comma after the logical_test, eg:
Code:
=IF(A1="hello",)

When both [value_if_true] and [value_if_false] arguments are omitted the function always returns 0 if the condition is met or FALSE() if the condition is not met (unless the condition references an error value in which case an error is returned).

Can anyone think of an instance where using the IF() function like this could be remotely useful?

Note - I'm comfortable with leaving one of these arguments out, just can't think of a valid application for leaving both out. Just a feeling in the back of my mind that the fact that IF() in this format is able to return different data types (number vs logical depending on condition=TRUE vs FALSE) might mean that there could be a clever use for it?

Cheers,
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Colin,

Very interesting. I never noticed that before.

My guess is that the IF() function evaluates two values, and returns a True (0) or False (FALSE) answer. This test without a ValueIfTrue/ValueIfFalse entry is essentially the equivalent of comparing the two values with an = operator. That is, =IF(A1=B1,) is the same as =A1=B1. The former returns a 0 or FALSE, whereas the latter returns a TRUE or FALSE.

The only reason I see for using IF() to test for equality between two values would be to impress your friends, amaze your enemies, and obfuscate the obvious.

JMHO
Russ
 
Upvote 0
I've known about this for quite a while, but until this post have not found a use for it, but I'm thinking the reason for 0 and FALSE is so that if you need a number for an array formula or FALSEs to be ignored in array formulas for example:

While you could do this with SUMPRODUCT, utilizing this you could do an array formula like so:

=COUNT(IF(LEFT(B1:B7,2)="AB",))

Confirm with CTRL-SHIFT-ENTER
 
Upvote 0
No idea if it's relevant but =ISNUMBER(FALSE) returns, well, FALSE.

But then again you can co-erce with --.:)
 
Upvote 0
Thank you all for your replies. :)

I think HOTPEPPER's suggestion is most inline with the sort of application I was considering - use in a CSE formula where a function which reads (zero) numbers but ignores booleans is aggregating the result, thereby concisely excluding unwanted elements.

It struck me that 0 vs FALSE seems like a slightly strange choice of 'default' outputs. I think I would have expected 1 and FALSE which might have been more useful?

Cheers,
 
Upvote 0
Here's my take on it, probably not right...

=IF(A1="hello",)

I'm thinking that by putting the comma there, the [value if true] argument is technically NOT actually omitted, but is given a NULL value, therefore treated as 0.

The same thing happens if you do this

=IF(A1="hello",,) <--- Notice 2 commas.
Niether argument is techically omitted, just given a Null value. yout get 0 whether A1 = hello or not, instead of 0 for true, false for false


Not sure if that's right, but that's my take on it...
 
Upvote 0
Hi Jon,

Sorry for the slow reply.

I think that is a very lucid observation. :)

I was a little bit mislead by the [ ] around the 2nd parameter, but the details in the helpfile clearly state it is required. Thanks for picking up on that.




I have another IF() 'observation' and I'd be appreciative if someone could double check this for me.

In Excel 2007, I set up the below worksheet with some simple constants and IF() calls. I deliberately didn't CSE enter the formulas.

It seems that IF() returns a result relative to the row position of the formula. If the formula's row takes it 'out of bounds' then a #VALUE! error is returned. So, E7:E8 return an error because B1:B5 doesn't have 7 & 8 rows, but E9 is okay because B1:B10 has enough rows. Similarly D11 has an error because A1:A10 doesn't have 11 rows.

Please can someone check if the same thing happens in Excel XP/2003?


Excel Workbook
ABCDE
11aaa
22bbb
30cFALSEc
4-1ddd
55eee
60fFALSEf
7-3gg#VALUE!
88hh#VALUE!
90iFALSEi
1010jj#VALUE!
11k#VALUE!#VALUE!
12l#VALUE!#VALUE!
13m#VALUE!#VALUE!
14n#VALUE!#VALUE!
Sheet1



Thanks
 
Upvote 0
I think that is just kind of a lazy man's function. I think it works in most simple functions. I tried it with a few, AND,IF,OR,EXACT,CONCATENATE.

Instead of having to type A and find the right Row#, a lazy person can just type A:A and it will refer to the row that the formula is entered in.

I think it is why some CSE formulas will still return a value (the wrong value) and not an error when NOT entered with CSE.
 
Upvote 0
I have my own mad "ideas" on this so (although most welcome) I'm not specifically looking for an explanation of the behaviour as such. Unfortunately I don't have Excel 2000/2002/2003 at home (which I need for my purposes) - so what I'm particularly hoping for is confirmation that this set-up produces the same or different results on these earlier versions?

Thanks
 
Upvote 0

Forum statistics

Threads
1,222,615
Messages
6,167,065
Members
452,093
Latest member
JamesFromAustin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top