How to convert date from text format to numeric number forma

ssunchen

New Member
Joined
Apr 19, 2002
Messages
17
Hi,

I am going to convert the date from text format to numeric number format. Like this:

08/22/1998 = 36029.

Could you teach me how to get it using VBA?

Thank you very much.

ssunchen
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Reasonably simple since VBA will take care of this conversion for you, here's an example:

<pre>
Public Sub main()

Dim oDate As Date
Dim iDate As Long

oDate = "08/22/1998"
iDate = oDate

MsgBox iDate

End Sub</pre>

oDate is the literal date, iDate is the date set as a long integer value.

HTH
 
Upvote 0
Hi,

This worked for me, after selecting the range you want to change.

Sub test()
Dim Rng As Range

For Each Rng In Selection

If IsNumeric(Rng) Then
Rng.NumberFormat = "General"
Else
On Error Resume Next
Rng = DateValue(Rng)
On Error GoTo 0
Rng.NumberFormat = "General"
End If
Next Rng
End Sub


Bye,
Jay
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,957
Latest member
Hat4Life

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