IF Statement Help...

Jav_uk8

New Member
Joined
Jan 12, 2017
Messages
22
Hi All,

I am trying to get the following IF statement to work but struggling.

I want the following to calculate the days between, if there is a date in T11 or Y11 (leave blank if empty). Then the second formula onwards is to calculate the amount of days between dates if in Q11 equals to M1, M2, D, E, MW or SV

=IF(AND(ISBLANK(T11),ISBLANK(Y11))," ",IF(Q11="M1",Y11-T11," ",IF(Q11="M2",Y11-T11," ",IF(Q11="D",Y11-T11," ",IF(Q11="E",Y11-T11," ",IF(Q11="MW",Y11-T11," ",IF(Q11="SV",Y11-T11," "))))

Hope this makes sense?

Jav
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi Jav,

Try this:
IF(AND(ISBLANK(T11),ISBLANK(Y11))," ",IF(Q11="M1",Y11-T11,IF(Q11="M2",Y11-T11,IF(Q11="D",Y11-T11,IF(Q11="E",Y11-T11,IF(Q11="MW",Y11-T11,IF(Q11="SV",Y11-T11," ")))))))

Your formula was closing the IF statements too many times, you were putting " " if false, and then opening another IF statement, to nest you have to keep using IF for the "value if false" parameter, and then end with " " when all of them are written! Hope this helps.
 
Last edited:
Upvote 0
Just noticed because it is always checking for Q11 to equal a value & the result if true is always Y11-T11 then you can shortern the formula and use this:
IF(AND(ISBLANK(T11),ISBLANK(Y11))," ",IF(OR(Q11="M1",Q11="M2",Q11="D",Q11="E",Q11="MW",Q11="SV"),Y11-T11," "))
 
Upvote 0
Hi tyija1995,

It has almost worked, the formula is trying to calculate the days between T - Y. Column T has a date but column Y is empty, the formula is returning -42974 (Because the date 27/08/2017 is entered in column T.

Jav
 
Upvote 0
If(and(t11<>"",y11<>""),if(or(q11="m1",q11="m2",q11="d",q11="e",q11="mw",q11="sv"),y11-t11,""))

You probably don't need a space if it fails, just a null.

Or even

IF(AND(T11<>"",Y11<>""),IF(ISNUMBER(SEARCH(Q11&",","M1,M2,D,E,MW,SV,")),Y11-T11,""))
 
Last edited:
Upvote 0
Ahh I see. That would be because you are essentially taking 0 - 27/08/2017 (which is 42974) as Excel does dates as numbers starting from 01/01/1900

Try this formula instead (Changed the AND to an OR at the start):
IF(OR(ISBLANK(T11),ISBLANK(Y11))," ",IF(OR(Q11="M1",Q11="M2",Q11="D",Q11="E",Q11="MW",Q11="SV"),Y11-T11," "))
 
Upvote 0
Hi,

Try this shorter version:

=IF(OR(T11="",Y11=""),"",IF(OR(Q11={"M1","M2","D","E","MW","SV"}),Y11-T11,""))

Note: Try not to use a Space ( " " ) as result, unless you have a Particular reason for doing so, it'll just cause problems down the road.
 
Upvote 0

Forum statistics

Threads
1,214,782
Messages
6,121,532
Members
449,037
Latest member
tmmotairi

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