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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,266
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,099,184
Messages
5,467,112
Members
406,524
Latest member
pascalschurink

This Week's Hot Topics

Top