Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Question about how dates in worksheets are typecast when used in V

I am trying to do a basic macro where I do some math on a series of dates to
determine the number of days between them. In some fields in the worksheet
there are entries and in some there are not. Because of this I only want to
do a calculation if both fields contain data. I find that in excel the
IsNumber() function will return if a date is in the field alright, but when I
try to use this line in an If statement in VBA:

Application.WorksheetFunction.IsNumber(Cells(row, col1).Value)

FALSE is always retuned. The cell I checked has 1/5/2005 in it. I used the
locals window to view the value of a temp variable I assigned and it shows
"#1/5/2005#".

Do I need to recast Cells(row,col1).Value as an integer and if so how do I
do it? Also is there a better way to do this?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Question about how dates in worksheets are typecast when used in V

In VBA there is a function IsNumeric... That might be the ticket here.
--
HTH...

Jim Thomlinson


"brent" wrote:

I am trying to do a basic macro where I do some math on a series of dates to
determine the number of days between them. In some fields in the worksheet
there are entries and in some there are not. Because of this I only want to
do a calculation if both fields contain data. I find that in excel the
IsNumber() function will return if a date is in the field alright, but when I
try to use this line in an If statement in VBA:

Application.WorksheetFunction.IsNumber(Cells(row, col1).Value)

FALSE is always retuned. The cell I checked has 1/5/2005 in it. I used the
locals window to view the value of a temp variable I assigned and it shows
"#1/5/2005#".

Do I need to recast Cells(row,col1).Value as an integer and if so how do I
do it? Also is there a better way to do this?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Question about how dates in worksheets are typecast when used

Jim that does work, additionally I also found that CLng() does a great job on
converting my date to a long so that I can check to see if it is blank (will
= 0).

"Jim Thomlinson" wrote:

In VBA there is a function IsNumeric... That might be the ticket here.
--
HTH...

Jim Thomlinson


"brent" wrote:

I am trying to do a basic macro where I do some math on a series of dates to
determine the number of days between them. In some fields in the worksheet
there are entries and in some there are not. Because of this I only want to
do a calculation if both fields contain data. I find that in excel the
IsNumber() function will return if a date is in the field alright, but when I
try to use this line in an If statement in VBA:

Application.WorksheetFunction.IsNumber(Cells(row, col1).Value)

FALSE is always retuned. The cell I checked has 1/5/2005 in it. I used the
locals window to view the value of a temp variable I assigned and it shows
"#1/5/2005#".

Do I need to recast Cells(row,col1).Value as an integer and if so how do I
do it? Also is there a better way to do this?

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
dates on worksheets Ann Excel Worksheet Functions 5 April 29th 10 04:45 PM
Sequential dates across worksheets Mick B Excel Discussion (Misc queries) 4 May 22nd 08 05:34 PM
changing dates in worksheets - help LEOPARDSHIDEAWAY Excel Discussion (Misc queries) 1 July 26th 07 10:06 PM
Moving dates between worksheets SuperDad Excel Discussion (Misc queries) 3 February 23rd 05 07:35 PM
Dates to Worksheets D[_2_] Excel Programming 5 February 2nd 05 03:30 AM


All times are GMT +1. The time now is 10:16 PM.

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

About Us

"It's about Microsoft Excel"