Testing for Date Format in VBA/Excel

G

Guest

I'm looking for a way to test, in an Excel VBA subroutine, whether a specific
cell value is (1) a numeric value that has been formated as date, (2) a
numeric value that has been formated as time, or (3) a "reggular" numeric
value.
 
V

Vijay Chary

Hi Jim, :) I think you should use the worksheet functions 'INFO' and 'CELL'
with appropriate arguments.
 
H

Hershmab

Tom Ogilvy said:
Use the Vartype function from VBA

See Excel VBA help for details.

I want to use this idea to create a UDF function "isdate", but my VBA
knowledge does not seem up to it: I created the following code in a new
module in my Personal.xls:

Public Function isdate(xCell As Range)
If VarType(xCell) = vbDate Then
isdate = True
Else
isdate = False
End If
End Function

I entered the formula "=isdate(B17)" in a cell, but it only returned
"#NAME?", and I did not know how to debug it. What am I doing wrong?
 
H

Hershmab

Thanks very much, a very simple solution!

A further question arising from this: is there any other place to store UDFs
so that I can use them without a worksheet qualifier, i.e just like Excel
worksheet functions?
 

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