Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default On time from cell time

Hi, I am using below code to do a task on a particular time as in a cell..

Application.OnTime TimeValue(CDate([Totals!O2])), "Assign"

But this takes the time whatever is there in the cell while workbook is
being opened, but I need to trigger a macro on time even after editing the
time in the cell.

Please help..

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default On time from cell time

Use a worksheet change to cancel old OnTime event and then set a new time.

Sub worksheet_change(ByVal target As Range)

For Each cell In target
If Not Application.Intersect(cell, Range("O2")) Is Nothing Then

'cancel old on time event
Application.OnTime _
EarliestTime:=0, _
procedu="Assign", _
schedule:=False

Application.OnTime _
EarliestTime:=TimeValue(target.Value), _
procedu="Assign", _
schedule:=True
End If
Next cell

End Sub


"Kash" wrote:

Hi, I am using below code to do a task on a particular time as in a cell..

Application.OnTime TimeValue(CDate([Totals!O2])), "Assign"

But this takes the time whatever is there in the cell while workbook is
being opened, but I need to trigger a macro on time even after editing the
time in the cell.

Please help..

Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default On time from cell time

I am getting below error

Method 'OnTime' of object'_Application' failed
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default On time from cell time

I'm not usre what line you are getting this problem. I suspect that you are
trying to clear the event before you have set the event. You may need to use
another cell to check if the timer has been set or not set. Maybe an OnError
statement

Sub worksheet_change(ByVal target As Range)

For Each cell In target
If Not Application.Intersect(cell, Range("O2")) Is Nothing Then

On Error Resume Next
'cancell old on time event
Application.OnTime _
EarliestTime:=0, _
procedu="Assign", _
schedule:=False
On Error GoTo 0
If Err.Number < 0 Then
Application.OnTime _
EarliestTime:=TimeValue(target.Value), _
procedu="Assign", _
schedule:=True
End If
End If
Next cell

End Sub





"Kash" wrote:

I am getting below error

Method 'OnTime' of object'_Application' failed

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default On time from cell time

I'm not able to get any output from the above code.. :(


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default On time from cell time

I added message boxes to the code below to help you debug the problem.

Sub worksheet_change(ByVal target As Range)

For Each cell In target
If Not Application.Intersect(cell, Range("O2")) Is Nothing Then

On Error Resume Next
msgbox("Cancel old on timer event")
Application.OnTime _
EarliestTime:=0, _
procedu="Assign", _
schedule:=False
On Error GoTo 0
If Err.Number < 0 Then
msgbox("Setting New Timer")
Application.OnTime _
EarliestTime:=TimeValue(target.Value), _
procedu="Assign", _
schedule:=True
else
msgbox("Error while clearing old event")
End If
End If
Next cell

End Sub



"Kash" wrote:

I'm not able to get any output from the above code.. :(

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default On time from cell time

I'm able to get both the msg

msgbox("Cancel old on timer event") & msgbox("Setting New Timer") but still
macro is not getting triggered.
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 174
Default On time from cell time

Hi Kash,

Did you activate the ontime event? Best is to put the application.ontime
statement in an event procedure of the workbook or worksheet.

Sub ontime()
Application.ontime EarliestTime:=Range("A10"), Procedu="Test"
End Sub

Sub test()
MsgBox Prompt:="hello"
End Sub

Wkr,

JP

"Kash" wrote in message
...
I'm able to get both the msg

msgbox("Cancel old on timer event") & msgbox("Setting New Timer") but
still
macro is not getting triggered.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
If statement to compare time cell to a time Z-Man-Cek Excel Worksheet Functions 16 July 29th 16 08:17 AM
Ok, one more thing, Pull just the Time out of a Time and Date Cell? nbaj2k[_14_] Excel Programming 4 July 27th 06 09:02 PM
time stamp a cell that doesn,t change when time stamping another RC Excel Programming 5 October 13th 05 02:52 AM
Extracting Time from a cell that has both the date and the time Hani Muhtadi Excel Discussion (Misc queries) 3 September 9th 05 10:59 AM
Adding time to date-time formatted cell tawtrey(remove this )@pacificfoods.com Excel Discussion (Misc queries) 4 August 12th 05 10:53 PM


All times are GMT +1. The time now is 09:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"