convert text to date

cloud168

New Member
Joined
Oct 12, 2009
Messages
19
Hi im trying to convert column A dates into date values as my dates contain text which cannot be converted by =datevalue() in excel

Im trying to write the following code but it doesnt work. Can anyone pls help?

Option Explicit

Sub converTextToDate()
Dim Current_Date As Date
Dim Date_String As Object
Dim myrange As Object
Dim DATERANGE As Object

Set myrange = ActiveSheet.Range("A6:A150")
Range("A6:A13").Select
Set DATERANGE = ActiveSheet.Range("A6:A150")
Date_String = Range("A6:A13").Value
Current_Date = CDate(Date_String)
Range("H6:H13").Select
Range("H6:H13").Value = Current_Date
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Have you tried "Text to Column"?


It doesnt work.

This code work but its only for a particular cell.
How do i make it to be a range of cells


Sub converTextToDate()

Dim Current_Date As Date
Dim Date_String As String

Range("A1").Select
Date_String = Range("A1").Value
Current_Date = CDate(date_String)
Range("C1").Select
Range("C1").Value = Current_Date

End Sub
</PRE>
 
Upvote 0
It doesnt work.

This code work but its only for a particular cell.
How do i make it to be a range of cells


Sub converTextToDate()

Dim Current_Date As Date
Dim Date_String As String

Range("A1").Select
Date_String = Range("A1").Value
Current_Date = CDate(date_String)
Range("C1").Select
Range("C1").Value = Current_Date

End Sub

</PRE>


Hi anyone kind enough to help me please
 
Upvote 0
Check the regional settings on your machine are correct for your environment, I have run into issues with this before where it would convert dates with a date of 1 to 12 but not higher as it thought it was a month when it was actually the day
 
Upvote 0
Check the regional settings on your machine are correct for your environment, I have run into issues with this before where it would convert dates with a date of 1 to 12 but not higher as it thought it was a month when it was actually the day

Hi mfexcel, the data are actually copied over from another system so the dates when copied into excel are in text format and when i try to use excel function =datevalue() it cant be converted nor can it be converted by text to column.

The steps are as follow

1) click text to column
2) next
3) next
4) click on tab date and choose MDY
5) finish

After i finish the steps it still doesnt have a value
 
Upvote 0
there may be some invisible character in your copied dates...

try the following to see...
=DATEVALUE(CLEAN(A1))
or
=DATEVALUE(SUBSTITUTE(A1,CHAR(160),""))

assume your date system is set at MDY

Good luck.


Hi mfexcel, the data are actually copied over from another system so the dates when copied into excel are in text format and when i try to use excel function =datevalue() it cant be converted nor can it be converted by text to column.

The steps are as follow

1) click text to column
2) next
3) next
4) click on tab date and choose MDY
5) finish

After i finish the steps it still doesnt have a value
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,457
Members
449,083
Latest member
Ava19

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