PDA

View Full Version : Copying real time data in excel using VBA



asquare007
05-18-2019, 12:50 AM
Hello - I am trying to copy real time data in subsequent rows whenever the data gets updated. I am using the following VBA code. This updates irrespective of any change. I only want it to change when the time stamp in cell A2 is updated. Any suggestions on how can I update this code?



Private Sub Worksheet_Calculate()
capturerow = 2
currow = Range("A65536").End(xlUp).Row
Cells(currow + 1, 1) = Cells(capturerow, 1)
Cells(currow + 1, 2) = Cells(capturerow, 2)
End Sub


Cheers

p45cal
05-18-2019, 07:06 AM
try (untested here):
Private Sub Worksheet_Calculate()
Static DTStamp
If DTStamp <> Range("A2") Then
capturerow = 2
currow = Range("A65536").End(xlUp).Row + 1
Cells(currow + 1, 1) = Cells(capturerow, 1)
Cells(currow + 1, 2) = Cells(capturerow, 2)
DTStamp = Range("A2")
End If
End Sub
Note that I've guessed you might need the +1.

大灰狼1976
05-21-2019, 02:01 AM
Hi asquare!
Welcome to vbax forum.

Private Sub Worksheet_Calculate()
capturerow = 2
currow = Range("A65536").End(xlUp).Row
Application.EnableEvents = False 'prevent ripple effects
Cells(currow + 1, 1) = Cells(capturerow, 1)
Cells(currow + 1, 2) = Cells(capturerow, 2)
Application.EnableEvents = True
End Sub