Consulting

Results 1 to 3 of 3

Thread: Copying real time data in excel using VBA

  1. #1

    Question Copying real time data in excel using VBA

    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
    Last edited by Aussiebear; 05-21-2019 at 02:09 AM. Reason: Added code tags to submitted code

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,872
    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.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •