vba - How do you link a time stamp to a cell using a userform button control? -
hello fellow vb developers/users/hobbyists. how you?
i have userform has 2 buttons:
- start
- stop
when press start, record current time in format dd/mm/yy hh:nn:ss in specific column.
then when press stop button record time again in cell next it.
then if press start again, record below first cell's current record. building timer record data see how long tasks take.
i post excel file , provide more information necessary.
thanks provided.
current code
public runtimer double public starttime date dim counter date sub setstart() counter = 0 starttime = runtimer = + timeserial(0, 0, 1) application.ontime runtimer, "setstart", , true set mytime = sheet4.range("f1") set timerng = sheet4.range("c8:c100") = worksheetfunction.counta(timerng) = + 1 cells(i, "c") = mytime sheet4.cells(i, "c").numberformat = "yyyy/mm/dd hh:mm:ss" if >= 2 cells(i, "d8") = cells(i, "c8") - cells(i - 1, "c8") sheet4.cells(i, "c").numberformat = "yyyy/mm/dd hh:mm:ss" end if application.enableevents = false end sub sub setstop() application.ontime runtimer, "setstop", , true set mytime = sheet4.range("f1") set timerng = sheet4.range("d8:d100") = worksheetfunction.counta(timerng) = + 1 application.enableevents = false cells(i, "d") = mytime sheet4.cells(i, "d").numberformat = "yyyy/mm/dd hh:mm:ss" end sub thank feedback , suggestions.
both of these work great. still having issue of recording data in specific worksheets within code. not want use current worksheet. sheet1 , start recording in cell "a8" opposed cell "a2"
thanks.
i've done similar keep track of how long sql , mdx queries take when run excel applications. users' sense of how long takes (it took 5 minutes!) , happened don't agree. need know how long things take either defend application or understand need optimize.
i set sheet mimic example. headers in row 1:
start time stop time elapsed time i have start button , stop button. assigned setstart start button , setstop stop button.
the code:
option explicit sub setstart() dim nextrow long nextrow = getlastrow("a") + 1 range("a" & nextrow) .value = .numberformat = "yyyy/mm/dd hh:mm:ss" end end sub sub setstop() dim nextrow long nextrow = getlastrow("b") + 1 range("b" & nextrow) .value = .numberformat = "yyyy/mm/dd hh:mm:ss" end calcelapsedtime (nextrow) end sub sub calcelapsedtime(nextrow long) range("c" & nextrow) .formula = "=b" & nextrow & "-a" & nextrow .numberformat = "hh:mm:ss" end end sub function getlastrow(columnletter string) long getlastrow = range(columnletter & activesheet.rows.count).end(xlup).row end function note not checking see if starts , stops done in correct sequence. if press start 3 times, continue add values in start column don't have matching stop times, foul elapsed times. if code i've provided you're after, you'll need add kind of logic app.
Comments
Post a Comment