Vba copy data every 5 minutes

ste33uka

Active Member
Joined
Jan 31, 2020
Messages
471
Office Version
  1. 365
Platform
  1. Windows
Hi would anyone have a vba that would copy data from cell F5 to F16 to H5 to H16 every 5 minutes and paste as values.
so data in F5 would copy to H5, F6 to H6 and so on,
Need it to run on 5 sheets
sheets are named 1,2,3,4,5
Thanks
 
Last edited:
i made new workbook, made 5 sheets named 1,2,3,4,5 and pasted code into "this workbook",
tried a few times , workbook wont open if i paste that code into it.
Very strange
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I think that the code will take 5 minuters to run?

Perhaps someone else will post some code to help you further?
 
Upvote 0
Hi again,

in your workbook:

VBA Code:
Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:05:00"), "runEveryFiveMinutes"
End Sub

In a module:

VBA Code:
Sub runEveryFiveMintutes()

Dim i As Integer

For i = 1 To 5

With Sheets(i)
     .range("F16").value = .range("F5").value
   
     .range("H16").value = range("H5").value
End With

Next i

Call runEveryFiveMinutes

End Sub
 
Upvote 0
Hi,

change the code to:

VBA Code:
Sub mySchedule()
Application.OnTime Now + TimeValue("00:05:00"), "runEveryFiveMinutes"
End Sub

and

VBA Code:
Sub runEveryFiveMintutes()

Dim i As Integer

For i = 1 To 5

With Sheets(i)
     .range("F16").value = .range("F5").value
   
     .range("H16").value = range("H5").value
End With

Next i

Call mySchedule

End Sub
 
Upvote 0
Hi,

change the code to:

VBA Code:
Sub mySchedule()
Application.OnTime Now + TimeValue("00:05:00"), "runEveryFiveMinutes"
End Sub

and

VBA Code:
Sub runEveryFiveMintutes()

Dim i As Integer

For i = 1 To 5

With Sheets(i)
     .range("F16").value = .range("F5").value
  
     .range("H16").value = range("H5").value
End With

Next i

Call mySchedule

End Sub
Thanks for helping , but nothing happens when i try that,
 
Upvote 0
Hi,

change the code to:

VBA Code:
Sub mySchedule()
Application.OnTime Now + TimeValue("00:05:00"), "runEveryFiveMinutes"
End Sub

and

VBA Code:
Sub runEveryFiveMintutes()

Dim i As Integer

For i = 1 To 5

With Sheets(i)
     .range("F16").value = .range("F5").value
  
     .range("H16").value = range("H5").value
End With

Next i

Call mySchedule

End Sub
it runs once if i remove "Call mySchedule" , but does not run every 5minutes
if i leave "Call mySchedule" in module, it wont work
 
Upvote 0
To run some code every 5 minutes put the following your workbook events:

VBA Code:
    Private Sub Workbook_Open()
        RunEveryFiveMinutes
    End Sub

And in a module you put the following sub:

VBA Code:
    Sub RunEveryFiveMinutes()
        //Add code here for whatever you want to happen
        Application.OnTime Now + TimeValue("00:05:00"), "RunEveryFiveMinutes"
    End Sub

You may also want to put in some code to kill the next scheduled run upon closing the workbook. I seem to remember something like this reopening my workbooks after I've closed them, but the details are a bit hazy.
 
Upvote 0
Solution
Thanks , that works,
is there any way to have 2 running so in workbook would look something like this,

Private Sub Workbook_Open()
RunEveryFiveMinutes
RunEveryTenMinutes
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,011
Messages
6,122,677
Members
449,092
Latest member
tayo4dgacorbanget

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