Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Auto Cell Format Change from General to Custom Date | Excel Discussion (Misc queries) | |||
how i change the default format cell from date to general ? | Excel Discussion (Misc queries) | |||
how to stop general format automatically changing to custom | Excel Discussion (Misc queries) | |||
changing date formatted as general number into date format | Excel Programming | |||
Date in userform being saved as general not date which affects sor | Excel Programming |