HELP! Run a macros on the hour, every hour automatically...

bapcki1

New Member
Joined
Nov 12, 2011
Messages
39
Hi Everyone!

I want to run a macros automatically on the hour, every hour.

Could anyone help with my following problem please?

I'm relatively new to VBA and I dont want someone to write a program for me so links to articles (and possibly a li'l bit of VBA code (if necessary)) would be great!

So far I have got code to update the =now() formula every minute:

ThisWorkBook:

Code:
Private Sub Workbook_Open()
    Dim CalcTime As String
    CalcTime = Format(WorksheetFunction. _
    Ceiling(Timer, 60) / 86400, "long time")
    Application.OnTime TimeValue(CalcTime), "UpdateTime"
End Sub

Module:

Code:
Public Sub UpdateTime()
    Range("I11").Calculate
    Application.OnTime Time + _
    TimeSerial(0, 1, 0), "UpdateTime"
End Sub
then by converting the time into minutes and using 24 =IF formulas, I have a cell, ( K36 ) that will = 1 on the hour, every hour.

With great help from Dave 3009, I have code to automatically run a macros IF cell K36 = 1 :

Code Module for the Sheet in question:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$K$36" Then Exit Sub
If Target.Value = 1 Then
    copytohere
End If
End Sub
ThisWorkBook:

Code:
Sub copytohere()
If ThisWorkbook.Sheets("Sheet1").Range("K36").Value = "1" Then
    Range("A1").Copy
    Range("E1").PasteSpecial xlPasteValues
    Range("A1").ClearContents
End If
ThisWorkbook.Sheets("Sheet1").Range("A4").Value = "0"
End Sub

Both sets of VBA code work perfectly on their own but I cant seem to get them to work together. Can anybody help please?


Paddy
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
If I understand the problem correctly, see
Schedule a Subroutine on a Periodic Basis Each Day
http://www.tushar-mehta.com/publish_train/xl_vba_cases/schedule_task_daily.htm
Hi Everyone!

I want to run a macros automatically on the hour, every hour.

Could anyone help with my following problem please?

I'm relatively new to VBA and I dont want someone to write a program for me so links to articles (and possibly a li'l bit of VBA code (if necessary)) would be great!

So far I have got code to update the =now() formula every minute:

ThisWorkBook:

Code:
Private Sub Workbook_Open()
    Dim CalcTime As String
    CalcTime = Format(WorksheetFunction. _
    Ceiling(Timer, 60) / 86400, "long time")
    Application.OnTime TimeValue(CalcTime), "UpdateTime"
End Sub

Module:

Code:
Public Sub UpdateTime()
    Range("I11").Calculate
    Application.OnTime Time + _
    TimeSerial(0, 1, 0), "UpdateTime"
End Sub
then by converting the time into minutes and using 24 =IF formulas, I have a cell, ( K36 ) that will = 1 on the hour, every hour.

With great help from Dave 3009, I have code to automatically run a macros IF cell K36 = 1 :

Code Module for the Sheet in question:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$K$36" Then Exit Sub
If Target.Value = 1 Then
    copytohere
End If
End Sub
ThisWorkBook:

Code:
Sub copytohere()
If ThisWorkbook.Sheets("Sheet1").Range("K36").Value = "1" Then
    Range("A1").Copy
    Range("E1").PasteSpecial xlPasteValues
    Range("A1").ClearContents
End If
ThisWorkbook.Sheets("Sheet1").Range("A4").Value = "0"
End Sub

Both sets of VBA code work perfectly on their own but I cant seem to get them to work together. Can anybody help please?


Paddy
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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