Month & year question

G

Guest

hello,

I have the following formula which works fine;

=IF(AND(L$1>=data!$K2, L$1<=data!$H2),
(IF(MONTH(L$1)=MONTH(data!$K2),$F2,data!$I2/data!$G2)),"")

I need to change it so that the bit (IF(MONTH(L$1)=MONTH(data!$K2) checks
that a date matches not only the month but the year also (i dont need to
match the day).

I tried this; - but excel says that it contains an error!

=IF(AND(L$1>=data!$K2, L$1<=data!$H2), (IF(MONTH(L$1),(YEAR
(L$1))=(MONTH(data!$K2)),(YEAR (L$1)),$F2,data!$I2/data!$G2)),"")

Any ideas how I can correct (IF(MONTH(L$1),(YEAR
(L$1))=(MONTH(data!$K2)),(YEAR (L$1)) to work?

many thanks

rgb
 
G

Guest

Hi

You'll need an AND in there. Try this:
=IF(AND(L$1>=data!$K2, L$1<=data!$H2),
(IF(AND(MONTH(L$1)=MONTH(data!$K2),YEAR(L$1)=YEAR(data!$K2)),$F2,data!$I2/data!$G2)),"")
untested.

Andy.
 
G

Guest

You may use the AND function there, as you did before
=IF(AND(L$1>=data!$K2, L$1<=data!$H2),
IF(AND(MONTH(L$1)=MONTH(data!$K2),YEAR(L$1)=YEAR(data!$K2)),$F2,data!$I2/data!$G2),"")

Hope this helps,
Miguel.
 
B

Bob Phillips

=IF(AND(L$1>=data!$K2, L$1<=data!$H2),
(IF(TEXT(L$1,"yyyymm")=TEXT(data!$K2,"yyyymm"),$F2,data!$I2/data!$G2)),"")

--
HTH

Bob Phillips

(replace xxxx in email address with googlemail if mailing direct)
 
G

Guest

Many thanks Miguel,

The formula still seems to have to exactly match the day part of $K2 to pull
through $F2 however. I need to match the year and month parts of $K2 only.

Cheers

RGB
 

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