Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Testing for Date Format in VBA/Excel

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Testing for Date Format in VBA/Excel

Use the Vartype function from VBA

See Excel VBA help for details.

--
Regards,
Tom Ogilvy


"Jim Watkins" wrote:

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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Testing for Date Format in VBA/Excel

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

"Jim Watkins" wrote:

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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Testing for Date Format in VBA/Excel



"Tom Ogilvy" wrote:

Use the Vartype function from VBA

See Excel VBA help for details.

--
Regards,
Tom Ogilvy


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?
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Testing for Date Format in VBA/Excel

=Personal.xls!isdate(B17)


Gord Dibben MS Excel MVP

On Wed, 7 Oct 2009 16:56:01 -0700, Hershmab
wrote:



"Tom Ogilvy" wrote:

Use the Vartype function from VBA

See Excel VBA help for details.

--
Regards,
Tom Ogilvy


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?




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Testing for Date Format in VBA/Excel

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?

"Gord Dibben" wrote:

=Personal.xls!isdate(B17)


Gord Dibben MS Excel MVP

On Wed, 7 Oct 2009 16:56:01 -0700, Hershmab
wrote:



"Tom Ogilvy" wrote:

Use the Vartype function from VBA

See Excel VBA help for details.

--
Regards,
Tom Ogilvy


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?



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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Format Problem - Date Overrides Format Mary Excel Discussion (Misc queries) 5 February 10th 10 05:49 AM
Excel 2000 date format cannot be set to Australian date format Brian Jones Excel Discussion (Misc queries) 1 March 30th 05 06:03 AM
Macro Date Testing BKBK Excel Programming 0 October 28th 04 05:42 PM
Testing Time /Date stamps of Files Tom Ogilvy Excel Programming 1 September 14th 03 07:49 PM
Testing Time /Date stamps of Files Tom Ogilvy Excel Programming 1 September 1st 03 05:38 PM


All times are GMT +1. The time now is 11:29 AM.

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"