Datepart problem
I'm using it in Excel VBA to sort previous and next year's dates.
Even using this simple code I get "application-defined or object-defined
error"
ActiveCell.Formula = "=if datepart((""yyyy"",[e2]) = ""00"",""N"",""y"""")"
I think I have braces in the wrong place
thanks
++++++++++++++++++++++++++
"Ron Rosenfeld" wrote in message
...
On Thu, 5 Jan 2006 20:59:05 +0100, "Ron Dean" wrote:
Can someone pick holes in this code as it fails.
ActiveCell.Formula = "=if datepart(""yyyy"",(e2)) =
datepart(""yyyy"",now()+1),date(1,month(e2),day( e2)),date(0,month(e2),day(e2))"
DATEPART is not an Excel worksheet function
Maybe you could replace it with the YEAR worksheet function.
Also, by entering either a 1 or a 0 as the first argument of the DATE
function,
this will give you either 1900 or 1901. Depending on what you are doing
with
this data, you may run into a problem as Excel believes that 29 Feb 1900
is a
legitimate date, and that there are 366 days in 1900.
--ron
|