Consulting

Results 1 to 5 of 5

Thread: Add value, as seconds, to LongDate

  1. #1

    Question Add value, as seconds, to LongDate

    Greetings!

    I'm working on some VBA for Excel 2003 currently and am having a bugger of a time with something. I'm trying to add the following:

    jCell = "09/24/2012 16:42:02"
    eCell = "30" which is to represent 30 seconds.

    My original equation is:
    [VBA]AnalysisWorkssheet.Range(dCell).Value = AnalysisWorksheet.Range(jCell).Value + Time(0, 0, AnalysisWorksheet.Range(eCell).Value)[/VBA]

    dCell = where I need it to go and in this example it should be "09/24/2012 16:42:32"

    I'm getting a <Type Mismatch> on the Time() portion, however when in debug mode, when I hover over the 'eCell' portion of the equation it IS showing the desired value that I would like added to "jCell".

    Anyone have any thoughts? I've been scouring the internet for several days on this one and have been mainly fruitless....

    THANKS!

    Any thoughts or suggestions?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [VBA] With AnalysisWorkssheet

    .Range(dCell).Value = .Range(jCell).Value + TimeSerial(0, 0, .Range(eCell).Value)
    End With
    [/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Xld,

    Thanks for the pointer, but I'm still not getting the desired results.

    Updated Code (disregard If/End If statement):[VBA]If AnalysisWorksheet.Range(jCell).Value <> AnalysisWorksheet.Range(NextJCell).Value Then
    ShowStartTime = AnalysisWorksheet.Range(jCell).Value
    AdToStartTime = TimeSerial(0, 0, AnalysisWorksheet.Range(eCell).Value)
    AdStartTime = ShowStartTime + AdToStartTime
    AnalysisWorkssheet.Range(dCell).Value = AdStartTime
    End If[/VBA]

    1. The math is correct, however, when attempted to set the value of dCell to be equal to AdStartTime, I now receive an "Object required" error. Debug mode shows the value as correct; albiet, it's not a string, just a Date. Is there a special process that one needs in order to set the value of a cell to this new variable value?

    2. Despite the math being correct, the time is being returned in 12hr format; for this project, it must be in 24hr format, no AM/PM distinction. Can this be done?



    Thanks again!

  4. #4
    HAHAHAHA!!! I'm an IDIOT!!!

    TYPO!!!

    AnalysisWorkssheet.Range(dCell).Value = AdStartTime
    ^ extra 's'

    Dur.... hehehehhehehe

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    If you had used With ... End With as I showed that would have been avoided/obvious.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •