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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,836
Office Version
  1. 2010
Platform
  1. Windows
Assuming i contains a valid row number,

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

ParamRay

Well-known Member
Joined
Aug 6, 2014
Messages
1,195
.
.

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

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,154
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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

RGButzArchInc

New Member
Joined
Aug 16, 2009
Messages
24
ADVERTISEMENT
Assuming i contains a valid row number,

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


Pleas forgive my lack of experience but why use the Cells object instead of h Range object in my code?
 
Upvote 0

RGButzArchInc

New Member
Joined
Aug 16, 2009
Messages
24
.
.

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,195,593
Messages
6,010,624
Members
441,558
Latest member
lambierules

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
Top