#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 9
Default If formula

Hello,
I have a formula here and I don't understand why it doesn't work. The
situation is such. I have a cell A1 that has a specfic date in it. If this
cell is an exact date that I deem as true then I want it to place the year
2007. If not, then I want it to place the text no. My formula is such:

=IF(A1="12-31-2007","2007","No")

Unfortunately my formula is wrong because I continue to get a "No" answer
when the cell A1 is that exact date of 12-31-2007. When I put a "<=" into
the formula, it works. I don't understand. Can someone help?

Thanks,
Chris
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 964
Default If formula

Dates in Excel are stored as serial numbers. Dec 31, 2007 is acutally stored
as the serial number 39447. Cell formatting may cause the serial number to
display as 12-31-2007, but the actual value of the cell is still 39447.

So, when your IF statement compares A1 to "12-31-2007", Excel compares the
serial number 39447 to the text string "12-31-2007" which obviously aren't
the same.

Try one of these formulas:

=IF(A1=DATE(2007,12,31),"2007","No")

or

=IF(TEXT(A1,"mm-dd-yyyy")="12-31-2007","2007","No")

The first option compares A1 to the serial number returned by the DATE
function. The second option converts A1 to a text string and then compares
to the text string "12-31-2007". Either way, this allows you to compare
apples to apples, instead of apples to oranges.

HTH,
Elkar


"kanstrup" wrote:

Hello,
I have a formula here and I don't understand why it doesn't work. The
situation is such. I have a cell A1 that has a specfic date in it. If this
cell is an exact date that I deem as true then I want it to place the year
2007. If not, then I want it to place the text no. My formula is such:

=IF(A1="12-31-2007","2007","No")

Unfortunately my formula is wrong because I continue to get a "No" answer
when the cell A1 is that exact date of 12-31-2007. When I put a "<=" into
the formula, it works. I don't understand. Can someone help?

Thanks,
Chris

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 9
Default If formula

Thanks so much Elkar. Make sense.

"Elkar" wrote:

Dates in Excel are stored as serial numbers. Dec 31, 2007 is acutally stored
as the serial number 39447. Cell formatting may cause the serial number to
display as 12-31-2007, but the actual value of the cell is still 39447.

So, when your IF statement compares A1 to "12-31-2007", Excel compares the
serial number 39447 to the text string "12-31-2007" which obviously aren't
the same.

Try one of these formulas:

=IF(A1=DATE(2007,12,31),"2007","No")

or

=IF(TEXT(A1,"mm-dd-yyyy")="12-31-2007","2007","No")

The first option compares A1 to the serial number returned by the DATE
function. The second option converts A1 to a text string and then compares
to the text string "12-31-2007". Either way, this allows you to compare
apples to apples, instead of apples to oranges.

HTH,
Elkar


"kanstrup" wrote:

Hello,
I have a formula here and I don't understand why it doesn't work. The
situation is such. I have a cell A1 that has a specfic date in it. If this
cell is an exact date that I deem as true then I want it to place the year
2007. If not, then I want it to place the text no. My formula is such:

=IF(A1="12-31-2007","2007","No")

Unfortunately my formula is wrong because I continue to get a "No" answer
when the cell A1 is that exact date of 12-31-2007. When I put a "<=" into
the formula, it works. I don't understand. Can someone help?

Thanks,
Chris

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,718
Default If formula

=IF(A1=39447,"2007","no")


"kanstrup" wrote:

Hello,
I have a formula here and I don't understand why it doesn't work. The
situation is such. I have a cell A1 that has a specfic date in it. If this
cell is an exact date that I deem as true then I want it to place the year
2007. If not, then I want it to place the text no. My formula is such:

=IF(A1="12-31-2007","2007","No")

Unfortunately my formula is wrong because I continue to get a "No" answer
when the cell A1 is that exact date of 12-31-2007. When I put a "<=" into
the formula, it works. I don't understand. Can someone help?

Thanks,
Chris

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"