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
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
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]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top