Data logging code is pasting data multiple times

BuffaloGuy

New Member
Joined
Dec 5, 2017
Messages
28
Every minute, this code copies Cells C3:M3 on the Calculation worksheet, and pastes it in the first available row on the Data worksheet.

The problem is, it pastes the code four times in a matter of seconds. Is there a way to stop the loop after one occurrence?

VBA Code:
Option Explicit

Dim TimeToRun


Sub MacroRun()

    TimeToRun = Now + TimeValue("00:01:00")
    Application.OnTime TimeToRun, "Macro1"
        
End Sub

Sub Macro1()
    Calculate
    
    ThisWorkbook.Worksheets("Calculation").Range("C3:M3").Copy
    
    ThisWorkbook.Worksheets("Data").Cells(Rows.Count, "C").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
    
    Application.CutCopyMode = False
        
MacroRun

End Sub


Sub stopMacros()
    
    On Error Resume Next
    Application.OnTime TimeToRun, "Macro1", , False
    
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
From the code you posted I don't see any reason why there would be more than one copy/paste per minute. Do you have other code, especially event code in the workbook?
 
Upvote 0
From the code you posted I don't see any reason why there would be more than one copy/paste per minute. Do you have other code, especially event code in the workbook?
I have this code as another module
VBA Code:
Sub AutoRefresh()
 
 ActiveWorkbook.RefreshAll
 
 'Auto-Refresh in 0 hours, 0 minute, 30 seconds
 
 NextTime = Time + TimeSerial(0, 0, 30)
 
 Application.OnTime NextTime, “AutoRefresh
 
End Sub
 
Upvote 0
I have this code as another module
VBA Code:
Sub AutoRefresh()

ActiveWorkbook.RefreshAll

'Auto-Refresh in 0 hours, 0 minute, 30 seconds

NextTime = Time + TimeSerial(0, 0, 30)

Application.OnTime NextTime, “AutoRefresh

End Sub
Actually this is the code.
VBA Code:
Sub AutoRefresh()
 
 ThisWorkbook.RefreshAll
 
 'Auto-Refresh in 0 hours, 0 minute, 30 seconds
 
 NextTime = Time + TimeSerial(0, 0, 30)
 
 Application.OnTime NextTime, “AutoRefresh”
 
End Sub
 
Upvote 0
I suspect your auto refresh is interfering with your copy/paste code. Can you combine the two, for example, start MacroRun with Thisworkbook.RefreshAll and remove the autorefresh module?
 
Upvote 0
That was my thought too, but I started working on my taxes and couldn’t work on it tonight. I’ll try it again tomorrow.
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

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