Copying excel rows from live data

asquare007

New Member
Joined
May 18, 2019
Messages
1
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
 

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,212
Welcome to MrExcel forums.

Try this:
Code:
Private Sub Worksheet_Calculate()
    Static previousTimestamp As Date
    Dim captureRow As Long, curRow As Long
    If Range("A2").Value <> previousTimestamp Then
        previousTimestamp = Range("A2").Value
        captureRow = 2
        curRow = Range("A65536").End(xlUp).Row
        Application.EnableEvents = False
        Cells(curRow + 1, 1) = Cells(captureRow, 1)
        Cells(curRow + 1, 2) = Cells(captureRow, 2)
        Application.EnableEvents = True
    End If
End Sub
PS - to get CODE tags for posting code click the # icon in the message editor and paste your code between them:

[CODE]your code here[/CODE]
 

Watch MrExcel Video

Forum statistics

Threads
1,095,726
Messages
5,446,151
Members
405,386
Latest member
xcookiemonster64

This Week's Hot Topics

Top