Hi Cperry,
Sorry for delay in reply I have been away. I have written some code which will do the add amount and decrement using 351 separate buffers as defined on your "previous _Working_exp " workbook
I haven' actually writtne any information back to the workbook because I didn't know what you wanted or where.
You were absolutely correct about my comment about writing to the columns to the right of Q. it is entirely unnecessary I was thinking you needed to record them.
Not the msgbox, is just for debug so you know where to look for the values in the 3 dimensional array G3darr
You must run "Init" first, you could do this on workbook open
Public G3darr(1 To 351, 1 To 30, 1 To 4) As Variant
Public prices() As Variant
Sub init()
For i = 1 To 351
For j = 1 To 30
For k = 1 To 4
G3darr(1, j, k) = ""
Next k
Next j
Next i
prices = Range(Cells(1, 13), Cells(351, 13))
End Sub
Sub Decrement()
timenow = Time()
sec30 = 1 / (24 * 60 * 2)
For p1 = 2 To 351
For i = 2 To 30
'Check Time
If G3darr(p1, i, 2) <> "" Then
timediff = Abs(timenow - G3darr(p1, i, 2))
If timediff > sec30 Then
For k = 1 To 4
G3darr(p1, i, k) = ""
Next k
Else
'Decrement
If G3darr(p1, i, 4) = "" Then
'First Iteration
G3darr(p1, i, 4) = G3darr(p1, i, 1) - G3darr(p1, i, 3)
Else
G3darr(p1, i, 4) = G3darr(p1, i, 4) - G3darr(p1, i, 3)
End If
End If
End If
Next i
Next p1
End Sub
Sub AddAmount()
amount = Cells(10, 11)
Price = Cells(9, 11)
' find buffer
For k = 1 To 351
If Price = prices(k, 1) Then
p1 = k
MsgBox (k)
Exit For
End If
Next k
For i = 2 To 30
If G3darr(p1, i, 1) = "" Then
'This is a blank row so populate it from j1
G3darr(p1, i, 1) = amount
G3darr(p1, i, 2) = Time()
G3darr(p1, i, 3) = G3darr(p1, i, 1) / 30
Exit For
End If
Next i
End Sub