Converting a Date to a number

RGButzArchInc

New Member
Joined
Aug 16, 2009
Messages
24
Usng VBA I wouldl ike to convert a date (string) to a serial number. I want to manipulate the number(s) arithmeticaly. The code in question is in a for next loop. i.e.

Current_Aspect -= Range("U & i")value.

I have tried using various funtions, both excel (application.value, etc) and VBA functions.I have also tried manpulating the data type to no avail. Any and all advice is greatly apprecited.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Assuming i contains a valid row number,

Code:
Current_Aspect = Cells(i, "U").Value
 
Upvote 0
.
.

You can achieve this in Excel by formatting the cell containing the date as "General".

Alternatively, you could use a formula such as =VALUE(TEXT(A1,"General"))
 
Upvote 0
Assuming i contains a valid row number,

Code:
Current_Aspect = Cells(i, "U").Value
For that to work, Current_Aspect must be declared as a Date variable.

If you leave Current_Aspect as a Variant, it gets assigned a String value as can be seen here...
Code:
Sub Test()
  Dim D As Variant
  D = Range("A1").Value
  MsgBox D + 1
End Sub
Change Variant to Date and the code will then work.
 
Upvote 0
.
.

You can achieve this in Excel by formatting the cell containing the date as "General".

Alternatively, you could use a formula such as =VALUE(TEXT(A1,"General"))

I would like to learn how to convert the date into an integer inorder to arithmaticaly manipulate said items.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,485
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top