ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   General Cell to Custom Date (https://www.excelbanter.com/excel-programming/384660-general-cell-custom-date.html)

[email protected]

General Cell to Custom Date
 
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!


Gary''s Student

General Cell to Custom Date
 
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
--
Gary's Student
gsnu200709


" wrote:

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!



Bill Kuunders

General Cell to Custom Date
 
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 ))


--
Greetings from New Zealand


wrote in message
ups.com...
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!





All times are GMT +1. The time now is 03:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com