Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Time is driving me crazy

Hello everyone!

I have a file that is generated on a second-by-second basis. Unfortunately,
it does not give me a time column, rather a 0,1,2,3,... column. It does give
me the start time, however, in this form:

Fri Jan 23 14:13:19 2009 (GMT-05:00).

My macro picks out the 14:13:19 using the Mid function, but after pasting
this to a column, I want to add one second to it and then extend it down for
the entire data set. I am having trouble adding one second to it. Here's my
macro thus far:


Sub TimeDilemma()

Range("D:D,F:F,H:H,J:J,L:L,N:N,P:P,R:R,T:T").Delet e Shift:=xlToLeft
'Cleans up my data

LastRow = Cells(Rows.Count, "A").End(xlUp).Row
TimeLength = Len(Range("A6").Value)
StartTime = Mid(Range("A6").Value, TimeLength - 24, 8)

Range("A8").Value = StartTime

'make Range("A9") = StartTime + 1 sec then autofill down?

Range("A8:A9").AutoFill Destination:=Range("A8:A" & LastRow)

End Sub


Any help would be greatly appreciated!

THANKS!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Time is driving me crazy

Excel should be treating the time you past in as a date. If you add one to a
date, you are adding a day:

Jan-01-2009 + 1 = Jan-02-2009

There are 24*60*60 seconds in a day. So, to add just one second, you need
to add a much smaller amount:

TimeNow = StartTime + 1# / 24# / 60# / 60#

Of course, you need to format that column as a time (something like HH:MN:SS)

HTH,

Eric

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Time is driving me crazy

Thank you egun! Question... why do I need the '#' after the numbers?

"egun" wrote:

Excel should be treating the time you past in as a date. If you add one to a
date, you are adding a day:

Jan-01-2009 + 1 = Jan-02-2009

There are 24*60*60 seconds in a day. So, to add just one second, you need
to add a much smaller amount:

TimeNow = StartTime + 1# / 24# / 60# / 60#

Of course, you need to format that column as a time (something like HH:MN:SS)

HTH,

Eric

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Time is driving me crazy

The #'s are type codes - indicating that the number is a Double
precision floating point value.

Of course, you don't need to do all the divisions, you could simply use

TimeNow = StartTIme + 1/86400#

or you can let VBA do the math:

TimeNow = StartTime + TimeSerial(0, 0, 1)



In article ,
Matt S wrote:

hank you egun! Question... why do I need the '#' after the numbers?

"egun" wrote:

Excel should be treating the time you past in as a date. If you add one to
a
date, you are adding a day:

Jan-01-2009 + 1 = Jan-02-2009

There are 24*60*60 seconds in a day. So, to add just one second, you need
to add a much smaller amount:

TimeNow = StartTime + 1# / 24# / 60# / 60#

Of course, you need to format that column as a time (something like
HH:MN:SS)

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
Driving me CRAZY~ please help Tara New Users to Excel 0 July 7th 08 07:29 PM
Sorry for reposting - but this is driving me crazy! Bean123r Excel Discussion (Misc queries) 1 January 27th 06 02:31 PM
Driving me crazy! RobEdgeler[_7_] Excel Programming 0 October 3rd 05 10:19 PM
It doesn't add up - It's driving me crazy Francis Hayes (The Excel Addict) Excel Programming 10 February 28th 05 10:40 PM
Driving me crazy! Dick Kusleika[_3_] Excel Programming 0 October 21st 03 10:18 PM


All times are GMT +1. The time now is 09:49 AM.

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

About Us

"It's about Microsoft Excel"