View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default need a function (not macro with ontime) to record a snapshot of a changing cell

Shannon,

Assumptions: The time to capture in entered in column B (entered as
time only), the value to capture is in column C, and the captured
value should be placed in column D (which will be empty until the
captured value is place in it). All cells are on the same row, all on
just one worksheet, the active worksheet.

Copy the code below into a module. Run "StartIt" to start, "StopIt" to
stop. Assign the macros to buttons or object for ease of starting and
stopping.

HTH,
Bernie
MS Excel MVP

Option Explicit
Dim NextTime As Date
Dim Running As Boolean

Sub StartIt()
Update
End Sub

Sub Update()
Dim myCell As Range
Running = True
'Check every second
NextTime = Time + TimeValue("00:00:01")
Application.OnTime NextTime, "Update"
For Each myCell In Intersect(Range("B:B"), ActiveSheet.UsedRange)
If myCell.Value < Time And myCell(1, 3).Value = "" Then
myCell(1, 3).Value = myCell(1, 2).Value
End If
Next myCell
End Sub

Sub StopIt()
If Not Running Then Exit Sub
On Error Resume Next
Application.OnTime NextTime, "Update", schedule:=False
Running = False
End Sub



"Shannon" wrote in message
om...
Bernie,

Thanks for the reply.

Last night I created a function with an module-level array variable
(500,6). The funtion dumps a new value to the array if the time is
less than or equal to the target snapshot time, else leaves the

array
alone. Then the funtion returns whatever is in the array.

This works, but is pretty slow and is taking up all my cpu

processing
power. I guess because the array is updating every time one of the
500x6 values changes (about every second), even after the target

time
has been passed.

I'm game to try your macro. Please let me know the next step.

Thanks.
Shannon