Hi all apologies, this is my first post so bear with me!
I'm running a macro in Excel which monitors values in a range of cells (say for arguments sake B2:C13) and if it sees any change in the cell, it will run another sub to copy the former values into a column (imagine it is for tracking stock prices)
in essence something like this:
The code above then runs the following separate macros
This works well - however, if I was to extend my data set, would there be a way of automating the "OldValue"s above? that are currently set using:
Or any other suggestions to be able to monitor a range and see if it changes to then run a code to copy across just that one cell or row into a specified column (i.e. as you can see the CopieValues macros all reference different columns)
Let me know if anyone has any good ideas or can help me out with my project.
Thanks in advance!
A
I'm running a macro in Excel which monitors values in a range of cells (say for arguments sake B2:C13) and if it sees any change in the cell, it will run another sub to copy the former values into a column (imagine it is for tracking stock prices)
in essence something like this:
Code:
Sub QuickOnTime()
Dim i As Long
Do 'infinite loop
For i = 1 To 1000000 ' Start loop.
If Not bLoop Then Exit Sub
'Range("G1") = Timer 'normally your RTD changes G1, this is just for the test, remove this row !!!!!
If Range("B2").Value <> OldValue Or Range("C2").Value <> OldValue1 Then
CopieValues
OldValue = Range("B2").Value 'save new value of G1
OldValue1 = Range("C2").Value
End If
If Range("B3").Value <> OldValue3 Or Range("C3").Value <> OldValue4 Then
CopieValues1
OldValue3 = Range("B3").Value 'save new value of G1
OldValue4 = Range("C3").Value
End If
If i Mod 10 = 0 Then ' If loop has repeated 100 times.
DoEvents ' Yield to operating system.
End If
Next i
Loop
End Sub
The code above then runs the following separate macros
Code:
Sub CopieValues()
Dim lRij As Long
lRij = Range("L" & Rows.count).End(xlUp).Row + 1 'last row with data
Range("L" & lRij).Resize(, 2).Value = Range("B2:C2").Value 'copy new values under last row
Range("K" & lRij).Value = Now() 'ev. save time
End Sub
Sub CopieValues1()
Dim lRij As Long
lRij = Range("O" & Rows.count).End(xlUp).Row + 1 'last row with data
Range("O" & lRij).Resize(, 2).Value = Range("B3:C3").Value 'copy new values under last row
Range("N" & lRij).Value = Now() 'ev. save time
End Sub
This works well - however, if I was to extend my data set, would there be a way of automating the "OldValue"s above? that are currently set using:
Code:
Public OldValue As Variant
Public OldValue1 As Variant
Or any other suggestions to be able to monitor a range and see if it changes to then run a code to copy across just that one cell or row into a specified column (i.e. as you can see the CopieValues macros all reference different columns)
Let me know if anyone has any good ideas or can help me out with my project.
Thanks in advance!
A