2009/5/21 Phil Hibbs <[email protected]>:
> There is no IsDate() function in OOo Calc, is there any way I can work
> around this? I want to write [=IF(IsDate(A1);A1;"")]
>
> Phil Hibbs.

I doubt that, since a date is only a number, and just about any number
COULD but doesn't have to be a date. Today, for example, is 39954.
40000 will be at 2009-07-06, by the way… How will we celebrate that…?
And why…?

Maybe it would be more relevant to test if the cell is formatted as a
date? This worked for me (parts of it ”stolen” from
http://www.oooforum.org/forum/viewtopic.phtml?t=28069):

Create the following function (as a OpenOffice.org BASIC macro):
REM  *****  BASIC  *****

Option Explicit

Function isDateTimeFormat(Row As Integer,Column As Integer) As Boolean
        Dim NumberFormat As Integer,NumberFormatType As Integer
        Dim oDoc As Object, oSheet As Object, oCell As Object
        Dim SheetNo As Integer
        
        oDoc=ThisComponent
        SheetNo=oDoc.CurrentSelection.getRangeAddress().Sheet
        oSheet=oDoc.Sheets.getByIndex(SheetNo)
        oCell=oSheet.getCellByPosition(Column-1,Row-1)
        
        NumberFormat=oCell.NumberFormat
        NumberFormatType=oDoc.getNumberFormats.getByKey(NumberFormat).Type
        isDateTimeFormat=NumberFormatType AND 
com.sun.star.util.NumberFormat.DATETIME
End Function

It's probably possible to do this in a better way, I don't know.

The reason why I typed
”SheetNo=oDoc.CurrentSelection.getRangeAddress().Sheet” instead of
”SheetNo=oDoc.CurrentSelection.getCellAddress().Sheet” is that the
”getCellAddress” thing doesn't exist if a cell range of more than one
cell is selected, which I guess could happen if a couple of cells are
highlighted and Ctrl+Shift+F9 is pressed. Well, just in case, you
know. Maybe there are other error sources in my function, though. I am
a beginner.

Now you probably want to know how to use the function, right?

Unfortunately yo ucan not use ”A1” as an argument, because the
function wants other things than the value of the cell. If A1 contains
5, then =MyFunction(A1) will do the same thing as =MyFunction(5).
That's not what we want.

Next idea was to give the cell name within quotes, like
=MyFunction("A1"), but then autofill won't work, so my solution was to
give row and column numbers as arguments. For A1, row=1 and column=1,
like this:
=MyFunction(1;1)
However, the same problem persists, that is that autofill won't work.
But there is a workaround: Just use the built in ROW and COLUMN
functions, like this:
=MyFunction(Row(A1);Column(A1))

This maybe look a bit too complicated, but it works and I just
couldn't find a better way. Yes, beginner, I know.

So the following will return TRUE or FALSE for cell A1:
=ISDATETIMEFORMAT(ROW(A1);COLUMN(A1))

I have tested this and it seems to work. However I'm not sure that
this is what you are asking for, but it took some time for a beginner
like me to create this…

If this is close to what you are looking for, and if you want to use
this in other spreadsheets, you can make that function global. I think
there are a lot of information out there how to do that, so I won't
mention it here unless you (or anyone) ask.

Kind regards

Johnny Rosenberg

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to