MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Dec 31st, 2003, 11:15 AM   #1
spendloa
 
Join Date: Jan 2003
Posts: 56
Default IF, AND, OR?

Good morning all...

Column C always holds a date and column D may (or may not) hold a date. Column E shows a number of days. What I would like to do is something like this:

Return a "1" -- if there is a date in culumn D (this should be checked first) AND the month in D = 1 AND E>8 OR if there is no date in culumn D AND the month in C = 1 AND E>8 -- otherwise return a "0"

I have this and can't work out what is wrong with it:

=IF(AND(MONTH(D5)=1,E5>8),1,IF(MONTH(D5)="",(IF(AND(MONTH(C5)=1,E5>8),1,0)),0))

It keeps returning 1's where they shouldn't be.

As usual, your assitance very much apprecated.
Happy new year!
Al
spendloa is offline   Reply With Quote
Old Dec 31st, 2003, 11:23 AM   #2
WillR
 
WillR's Avatar
 
Join Date: Feb 2002
Location: Sutton Coldfield
Posts: 1,140
Default Re: IF, AND, OR?

Try this

=IF(OR(AND(MONTH(D5)=1,E5>8),(AND(MONTH(D5)="",MONTH(C5)=1,E5>8))),1,0)

Hope it helps
__________________
/**\ Regards, Will /**\
WillR is offline   Reply With Quote
Old Dec 31st, 2003, 11:36 AM   #3
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 39,503
Default Re: IF, AND, OR?

=IF(AND(D5<>"",MONTH(D5)=1,E5>8),1,0)

or better:

=(D5<>"")*(MONTH(D5)=1)*(E5>8)

WillR's will be troubled when D5 is empty. However, the foregoing is not trouble-free. A 1 in D5 will pass the MONTH test.
Aladin Akyurek is offline   Reply With Quote
Old Dec 31st, 2003, 11:37 AM   #4
spendloa
 
Join Date: Jan 2003
Posts: 56
Default Re: IF, AND, OR?

Cheers, we have sorted it now with the following:

=IF(AND(MONTH($D9)=1,AD9>8,D9>0),"1",IF(AND($D9=0,MONTH($C9)=1,AD9>8),"1","0"))


The problems occured because excel returns a 1 from the "month" function even when there is no date present.

Thanks again
spendloa is offline   Reply With Quote
Old Dec 31st, 2003, 11:41 AM   #5
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 39,503
Default Re: IF, AND, OR?

Quote:
Originally Posted by spendloa
Cheers, we have sorted it now with the following:

=IF(AND(MONTH($D9)=1,AD9>8,D9>0),"1",IF(AND($D9=0,MONTH($C9)=1,AD9>8),"1","0"))


The problems occured because excel returns a 1 from the "month" function even when there is no date present.

Thanks again
You don't need to be that long. See my post. BTW, it's not good idea putting 1 and 0 in between double quotes which transform into non-numbers.
Aladin Akyurek is offline   Reply With Quote
Old Dec 31st, 2003, 06:27 PM   #6
WillR
 
WillR's Avatar
 
Join Date: Feb 2002
Location: Sutton Coldfield
Posts: 1,140
Default Re: IF, AND, OR?

Quote:
Originally Posted by Aladin Akyurek
=IF(AND(D5<>"",MONTH(D5)=1,E5>8),1,0)

or better:

=(D5<>"")*(MONTH(D5)=1)*(E5>8)

WillR's will be troubled when D5 is empty. However, the foregoing is not trouble-free. A 1 in D5 will pass the MONTH test.
Aladin,

Can I ask how your formulas deal with the fact that if D5 has no data, then a 1 should still be returned by the formula if C5's month is = 1 ? I admit your formulas are much cleaner than my effor, however I can't see the C5 evaluation.

Will
__________________
/**\ Regards, Will /**\
WillR is offline   Reply With Quote
Old Dec 31st, 2003, 06:44 PM   #7
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 39,503
Default Re: IF, AND, OR?

Quote:
Originally Posted by WillR
Quote:
Originally Posted by Aladin Akyurek
=IF(AND(D5<>"",MONTH(D5)=1,E5>8),1,0)

or better:

=(D5<>"")*(MONTH(D5)=1)*(E5>8)

WillR's will be troubled when D5 is empty. However, the foregoing is not trouble-free. A 1 in D5 will pass the MONTH test.
Aladin,

Can I ask how your formulas deal with the fact that if D5 has no data, then a 1 should still be returned by the formula if C5's month is = 1 ? I admit your formulas are much cleaner than my effor, however I can't see the C5 evaluation.

Will
Getting sloppy I guess. I didn't see the C5 bit...

My point was that we need to include a non-empty test regarding cells expected to have a date. As I pointed out, it's a weak test, but better than none.
Aladin Akyurek is offline   Reply With Quote
Old Dec 31st, 2003, 07:05 PM   #8
WillR
 
WillR's Avatar
 
Join Date: Feb 2002
Location: Sutton Coldfield
Posts: 1,140
Default Re: IF, AND, OR?

I totally agree with your approach... much cleaner then mine.. I just thought I was going a bit mad over the C5 bit (that maybe you'd discovered some form of "cloaking" device in a formula)..

Thanks for pointing it out
__________________
/**\ Regards, Will /**\
WillR is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 03:48 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.