VBA Help to Copy a Cell Value every 2 minutes

jenningstrades

New Member
Joined
Oct 22, 2024
Messages
3
Office Version
  1. 2021
Platform
  1. Windows
Hello,

I have a set of values that update in real time. I am trying to create a graph with the data overtime. I am new to excel and have value that I would like to copy every 2 minutes in cells F3 and G3. I would like to have the value copied every 2 minutes into a column with time stamps. How can I accomplish this?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
VBA Code:
Option Explicit

Dim TimeToRun

Sub chkTimer()
    Application.DisplayAlerts = False
    TimeToRun = Now + TimeValue("00:2:00")
    Application.OnTime TimeToRun, "runMacro"
    Application.DisplayAlerts = True
End Sub

Sub runMacro()
    Calculate
    Sheet1.Range("F3:G3").Copy Destination:=Sheet1.Range("K3")
    Sheet1.Range("N3") = Format(Now, "hh:mm:ss")
   
    chkTimer
End Sub

Sub stopMacro()
    On Error Resume Next
    Application.OnTime TimeToRun, "runMacro", , False
End Sub
 
Upvote 0
VBA Code:
Option Explicit

Dim TimeToRun

Sub chkTimer()
    Application.DisplayAlerts = False
    TimeToRun = Now + TimeValue("00:2:00")
    Application.OnTime TimeToRun, "runMacro"
    Application.DisplayAlerts = True
End Sub

Sub runMacro()
    Calculate
    Sheet1.Range("F3:G3").Copy Destination:=Sheet1.Range("K3")
    Sheet1.Range("N3") = Format(Now, "hh:mm:ss")
  
    chkTimer
End Sub

Sub stopMacro()
    On Error Resume Next
    Application.OnTime TimeToRun, "runMacro", , False
End Sub
I tested this one out this morning. The code worked to copy the information, however it refreshed the same cell repeatedly. It is possible to get this to paste each value into the following row in the for each refresh? Also it is pasting the formula in the cell as well. It is possible that it can do the value only?
 
Upvote 0
VBA Code:
Option Explicit

Dim TimeToRun

Sub chkTimer()
    Application.DisplayAlerts = False
    TimeToRun = Now + TimeValue("00:0:05")
    Application.OnTime TimeToRun, "runMacro"
    Application.DisplayAlerts = True
End Sub

Sub runMacro()
Application.ScreenUpdating = False
    Calculate
    Sheet1.Range("F3:G3").Copy 'Destination:=Sheet1.Range("K3")
    'Sheet1.Range("N3") = Format(Now, "hh:mm:ss")
    Sheet1.Cells(Rows.Count, 11).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
    Sheet1.Cells(Rows.Count, 14).End(xlUp).Offset(1, 0) = Format(Now, "hh:mm:ss")
    Application.CutCopyMode = False
Application.ScreenUpdating = True

    chkTimer
End Sub

Sub stopMacro()
    On Error Resume Next
    Application.OnTime TimeToRun, "runMacro", , False
End Sub
 
Upvote 1
Solution
VBA Code:
Option Explicit

Dim TimeToRun

Sub chkTimer()
    Application.DisplayAlerts = False
    TimeToRun = Now + TimeValue("00:0:05")
    Application.OnTime TimeToRun, "runMacro"
    Application.DisplayAlerts = True
End Sub

Sub runMacro()
Application.ScreenUpdating = False
    Calculate
    Sheet1.Range("F3:G3").Copy 'Destination:=Sheet1.Range("K3")
    'Sheet1.Range("N3") = Format(Now, "hh:mm:ss")
    Sheet1.Cells(Rows.Count, 11).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
    Sheet1.Cells(Rows.Count, 14).End(xlUp).Offset(1, 0) = Format(Now, "hh:mm:ss")
    Application.CutCopyMode = False
Application.ScreenUpdating = True

    chkTimer
End Sub

Sub stopMacro()
    On Error Resume Next
    Application.OnTime TimeToRun, "runMacro", , False
End Sub
Wow great stuff! It is working like a charm now. Thanks a ton!
 

Attachments

  • Screenshot 2024-10-24 112026.png
    Screenshot 2024-10-24 112026.png
    77.8 KB · Views: 2
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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