Jump to content

Excel Increment Help


 Share

Recommended Posts

Hey guys, I am trying to write to excel with time increasing by 1 second.. and I feel like I've made it super complicated and also it still messes up because I need the time in the XX:XX:XX format and when it's 12:11:01 it just writes 12:11:1. I just need to set time in Cell B7 - Bxx to time now plus one second for each cell, where XX is decided by the user. 

$lastrow = InputBox("Last Row is?", "What is the last row used?")
    _Excel_RangeWrite($oExcel, "ELISA", "546_UCMR4", "A7:A" & $lastrow) ;Fill in Test Code

    $timeStarted = _NowCalc()
    For $i = 7 To $lastrow
        $sNowTime = _DateAdd('s', $i, $timeStarted)
        Local $aMyDate, $aMyTime
        _DateTimeSplit($sNowTime, $aMyDate, $aMyTime)
        $timenotdate = $aMyTime[1] & ":" & $aMyTime[2] & ":" & $aMyTime[3]
        $timeincremented = _DateTimeFormat($sNowTime, 2) & " " & $timenotdate & " PM"
        ConsoleWrite($timeincremented & @CRLF)
        _Excel_RangeWrite($oExcel, "ELISA", $timeincremented, "B" & $i) ;Fill in Time
    Next

 

Link to comment
Share on other sites

2 minutes ago, Subz said:

You could just use something like:

StringFormat("%02i:%02i:%02i", @HOUR, @MIN, @SEC + 1)

 

HAH! Brilliant, had to adjust for seconds > 60 but I fixed it for up to 120seconds which is fine for me! It's not as elegant as your single line of script.. but, it works! Thanks dude, you rock!

$timeStarted = _NowCalc()
    For $i = 7 To $lastrow
        $sNowTime = _DateAdd('s', $i, $timeStarted)
        $seconds = @SEC + $i
        $minutes = @MIN
        If $seconds > 60 AND $seconds < 120 Then
            $seconds = $seconds - 60
            $minutes = $minutes + 1
        EndIf

        If $seconds > 120 Then
            $seconds = $seconds - 120
            $minutes = $minutes + 2
        EndIf

        $suggestedtime = StringFormat("%02i:%02i:%02i", @HOUR, $minutes, $seconds)
        $timeincremented = _DateTimeFormat($sNowTime, 2) & " " & $suggestedtime & " PM"
        ConsoleWrite($timeincremented & @CRLF)
        _Excel_RangeWrite($oExcel, "ELISA", $timeincremented, "B" & $i) ;Fill in Time
    Next

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...