Date Between IF And Statement

P

Paperback Writer

Can someone help with my logic? I can't seem to figure this out.

I want it to say "2005" if the date is between 12/31/2004 and 01/01/2006. I
keep getting an error.

Here is my formula.

IF((AND(D2>DATE(2004,12,31)),(D2<DATE(2006,1,1))),"2005","NO")
 
J

John C

You have too many parentheses:
IF(AND((D2>DATE(2004,12,31),(D2<DATE(2006,1,1)),"2005","NO")

but a better formula might be:
=IF(YEAR(D2)=2005,2005,"NO")
 
P

Paperback Writer

I plug in the formula, and I still get a problem

IF(AND((D2>DATE(2004,12,31),(D2<DATE(2006,1,1)),"2005","NO")

Is this the corrected formula?

I can't use yours because it is year specific. I need variants that will
allow me to specify dates.

Thanks!!
 
P

Paperback Writer

One more thing. The formula involves columns D and E.

REVISED

IF(AND((D2>DATE(2004,12,31),(E2<DATE(2006,1,1)),"2005","NO")

Still having problems. :(
 
J

John C

Try this correction: (I had untested prior).
=IF(AND(D2>DATE(2004,12,31),D2<DATE(2006,1,1)),2005,"NO")

This should work.

I can modify my other formula as well, say, for example, the year specific
that you are looking for is in cell H1, you could use this formula, and
modify the year as needed:
=IF(YEAR(D2)=$H$1,$H$1,"NO")
All you would need to do is type the year that you are checking for, in this
case, 2005.
 
D

David Biddulph

You've still got your parentheses wrong. Go through the formula and check
which pairs match. Excel will usually colour the parentheses (while you are
editing the formula) to help you in this process.

Try =IF(AND(D2>DATE(2004,12,31),D2<DATE(2006,1,1)),"2005","NO")
 
B

Bob Phillips

It is no more specific than yours. Plug 2005 into a cell, and it is a simple
change

=IF(YEAR(D2)=$M$1,$M$1,"No")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top