ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Question about how dates in worksheets are typecast when used in V (https://www.excelbanter.com/excel-programming/341882-question-about-how-dates-worksheets-typecast-when-used-v.html)

Brent

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?

Jim Thomlinson[_4_]

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?


Brent

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?



All times are GMT +1. The time now is 02:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com