Thanks for this foxguy, I've been looking at this all morning but it seems it's not populating the array correctly.I had 2 cols of values for 50 rows and then the function in the 3rd col. It returned the time nicely and updated every time I manually changed a value but I couldn't get it further than initializing the array to test comparing the values.
I placed a break at Trigger = vArr to see how the array was populating in the Locals window and this is what it looked like:
Screenshot of Locals window
Also, is the code to compare rCells2Check values versus corresponding values in the array accurate?
Function Trigger(ByVal rCells2Check As Range) As Date
Application.Volatile False
If rCells2Check.Rows.Count > 1 Then
MsgBox "This Function Will Only Work On 1 Row"
Exit Function
End If
'create variable that will will hold values between triggers
Static vArr As Variant
Dim Index As Integer
Dim YesNo As String
Dim Price As Double
Dim lCols As Long
Dim lCol As Long
'Tell VBA where to go if an error occurrs
On Error GoTo EF
'Turn off features that slow things down
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
'Ignore next error
On Error Resume Next
'check to see if the array exists
lCols = UBound(vArr, 1)
'reset On Error
On Error GoTo EF
'Assign row number as unique index number and YesNo and Price values from range
Index = rCells2Check.Row
YesNo = rCells2Check(1).Value
Price = rCells2Check(2).Value
If lCols <> rCells2Check.Columns.Count Then
'either vArr has not been initialized
'or the user has changed the # of columns to check
ReDim vArr(1 To 1, 1 To 1)
'just create a blank array to get things started
End If
If UBound(vArr, 2) < Index Then
'add a new column to array if this data row has not been created yet
ReDim Preserve vArr(1 To lCols, 1 To Index)
'put the values from rCells2Check into the correct column in array
For lCol = 1 To lCols
vArr(lCol, Index) = rCells2Check.Columns(lCol).Value
Next
'Trigger = vArr
Else
'vArr was already initilized so check values
If rCells2Check.Columns(lCol).Value <> vArr(lCol, Index) Then
MsgBox "Value in one of the cells has changed"
End If
End If
EF:
'Turn Features back on
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
'return the data & time to put into the cell with "=Trigger(.....)" in it.
Trigger = Now
End Function
Bookmarks