General Cell to Custom Date

K

karicramer

I'm just learning VBA, and Need some help w/ a macro that will format
the date I have in a number of text files.

Presently the data is coming to me as a general format of
"20060103123030" I presently format the cell to custom yyyy/mm/dd
hh:mm:ss and then I type in the slashes & colons, Does anyone have an
idea of how I could write some code that could do this for me? Any
help is greatly appreciated.

Thanks,
Kdub, the vba newbie!
 
G

Guest

With your data in A1, try:

Sub dural()
Dim s As String
s = Range("A1").Value
y = Left(s, 4)
m = Mid(s, 5, 2)
d = Mid(s, 7, 2)
h = Mid(s, 9, 2) * 1
mint = Mid(s, 11, 2) * 1
sec = Mid(s, 13, 2) * 1

x = DateSerial(y, m, d) * 1
x = x + h / 24 + mint / 1440 + sec / 86400

Range("A1").Clear
Range("A1").NumberFormat = "yyyy/mm/dd hh:mm:ss"
Range("A1").Value = x
End Sub
 
B

Bill Kuunders

There must be someone who can write you code to do this ...

My solution here is a "simple " formula in a help column next to the entry
column.

You can -after entry- change the formula's to a value, with the "copy ,
paste special , values" routine.

Say your dates are entered in "text" format in column A
have the B column in "general' format and enter the formula....

=CONCATENATE(MID(A1,1,4),"/",MID(A1,5,2),"/",MID(A1,7,2),"
",MID(A1,9,2),":",MID(A1,11,2),":",MID(A1,13,2))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top