Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 303
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Cell Format Change from General to Custom Date ejschmitt2000 Excel Discussion (Misc queries) 1 September 11th 09 09:31 PM
how i change the default format cell from date to general ? as Excel Discussion (Misc queries) 0 June 3rd 09 07:26 AM
how to stop general format automatically changing to custom Cori Excel Discussion (Misc queries) 3 June 7th 08 07:22 PM
changing date formatted as general number into date format pghio Excel Programming 4 March 2nd 07 05:17 PM
Date in userform being saved as general not date which affects sor Michael Malinsky[_3_] Excel Programming 0 July 28th 04 06:58 PM


All times are GMT +1. The time now is 10:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"