Data type conversion.

Caula

New Member
Joined
Aug 6, 2010
Messages
46
I have a column of text strings that looks like short dates but when I check the cell type it comes ou as text.
I'm after the VBA code to convert such text strings to the equivalent date and date data type.
What is the best way to achieve that? Any suggestions?

Thanks,

Claula
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Very simple: I have this text "02/02/2015" in any range and want to convert it to Date type.
 
Upvote 0
Do you have to use VB to do this? How about a simple manual method? Select the column with your text dates in them, then call up the Text To Columns dialog box (Data tab, Data Tools group, Text To Columns button) and as soon as the dialog box appears, click the Finish button... you should now be able to use Cell Formatting to make the resulting date serial numbers look like whatever date format you want.
 
Upvote 0
Thanks for your hel Rick!

The reason I want to do that with VBA is because I need to loop through a counlumn with tens od thousands of these texts. The data will be updates every month and I'll be repeating this operation periodically.

All I need is the function or best way to go about that and I'll be able to write the Sub. I saw somewhere a function named "CDate" which I've never used before. Is this the way to go?

Thanks again Rick
 
Upvote 0
Thanks for your hel Rick!

The reason I want to do that with VBA is because I need to loop through a counlumn with tens od thousands of these texts. The data will be updates every month and I'll be repeating this operation periodically.

All I need is the function or best way to go about that and I'll be able to write the Sub.
Here is the code line (there is only one) that does the same thing as the manual method I posted about. Let's assume the column with your text dates in them is Column G, then the code line to convert them to real dates is this...
Code:
Columns("Q").TextToColumns Other:=False
 
Upvote 0

Forum statistics

Threads
1,214,387
Messages
6,119,222
Members
448,877
Latest member
gb24

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