run my code in every 15 min

Dipak543

New Member
Joined
Jul 4, 2020
Messages
26
Office Version
  1. 365
Platform
  1. Windows
M not able to run this code in every 15 min ...someone pls help me ... the code start at 9;15 am and it's copy the value in every second from RTD data from Column 2 (in subsequent rows) but i want that the code copy data in every 15 min only. Suppose at 9:30 am the code starts and copy the value and then stop automatically its repeat the process in every 15 min till 15:30.

Private Sub Worksheet_Calculate()
If Time >= TimeSerial(15, 29, 59) And Time <= TimeSerial(15, 30, 0) Then

capturerow = 2

currow = Range("A65536").End(xlUp).Row

Cells(currow + 1, 1) = Cells(capturerow, 1)
Cells(currow + 1, 2) = Cells(capturerow, 2)
Cells(currow + 1, 3) = Cells(capturerow, 3)
Cells(currow + 1, 4) = Cells(capturerow, 4)
Cells(currow + 1, 5) = Cells(capturerow, 5)


Else
Exit Sub
End If

End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I tried this but its not working
1593895377214.png
 
Upvote 0
.
VBA Code:
Option Explicit

Public RunWhen As Double
Public Const cRunIntervalSeconds = 900    ' 1800 seconds = 30 min.   30 x 60 = 1800
Public Const cRunWhat = "Worksheet_Calculate"         ' the name of the procedure to run
Private TimerEnabled As Boolean             ' This value can only be changed by code in this module

Sub StartTimer()
    TimerEnabled = True
    RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
    Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, Schedule:=True
End Sub

Sub RunIt()
    Dim Crng As Range, Prng As Range
    Dim StartTime As String
    Dim StopTime As String
    Dim CurrentTime As String
    CurrentTime = Time
   
    StartTime = "9:30:00 AM"
    StopTime = "15:30:00 PM"
   
    If CurrentTime >= StartTime Then
        If CurrentTime >= StopTime Then
            Call StopTimer
        Else
            If TimerEnabled Then StartTimer
        End If
    Else
   
        'Call to YOUR MACRO goes here
        'Example : If you macro name is MyMacro ... then you would place Call MyMacro in this line
       
         Call  Worksheet_Calculate

        If TimerEnabled Then StartTimer
    End If
End Sub

Sub StopTimer()
    On Error Resume Next
    TimerEnabled = False
    Application.OnTime EarliestTime:=Now(), Procedure:=cRunWhat, Schedule:=False
End Sub
 
Upvote 0
Thank you for your quick reply sir, actually, I am a newbie in VBA and I tried to use this code but it's showing an error, I attached the Photo pls
Screenshot (225).png
Screenshot (226).png
go through it
 
Upvote 0
.
You'll need to move Sub Worksheet_Calculate() to a REGULAR MODULE and rename the macro to something else.

Also, the TIMER macro should be in a REGULAR MODULE as well.

You'll also need to remove the 'timer' portion of that macro ( If Time >= TimeSerial(15, 29, 59) And Time <= TimeSerial(15, 30, 0) Then ) since
the other timer macro is doing the time keeping now.
 
Upvote 0
thank you so much logit finally it's worked...tomorrow I will check in live market
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,189
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