ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Convert date to serial number in VBA (https://www.excelbanter.com/excel-programming/276658-convert-date-serial-number-vba.html)

Michael J. Malinsky

Convert date to serial number in VBA
 
I have a couple of dates that are input via UserForm and are then used in
VBA calculations. Something like EndDate-BeginDate+1 gives the number of
days (so January 31, 2003 minus January 1, 2003 results in 31 days). Due to
calculations elsewhere in my code, this doesn't seem to be doing the trick.
What I'd like to do within VBA is covert the dates to serial numbers so
September 10, 2003 would be converted to 37874 before any calculations are
performed. I've look high and low and can't find help on the boards or in
the knowledge base or in help. Either its not there or I fried my brain.

TIA.
Mike.

--
Michael J. Malinsky




steve

Convert date to serial number in VBA
 
Michael,

Take a look at how you input the date in the form. The output of a textbox
is text and has to be reconverted to numeric.
Try something like
myvar = Val(MyForm.TextBox1.Value)

--
sb
"Michael J. Malinsky" wrote in message
...
I have a couple of dates that are input via UserForm and are then used in
VBA calculations. Something like EndDate-BeginDate+1 gives the number of
days (so January 31, 2003 minus January 1, 2003 results in 31 days). Due

to
calculations elsewhere in my code, this doesn't seem to be doing the

trick.
What I'd like to do within VBA is covert the dates to serial numbers so
September 10, 2003 would be converted to 37874 before any calculations are
performed. I've look high and low and can't find help on the boards or in
the knowledge base or in help. Either its not there or I fried my brain.

TIA.
Mike.

--
Michael J. Malinsky







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

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