TimeValue issue

adeel1
3StarLounger
Posts: 264
Joined: 04 Oct 2017, 15:47

TimeValue issue

Post by adeel1 »

Hi All


please see why below line is turning into error, sample attached

Code: Select all

Application.OnTime Now + TimeValue("00:" & ss.Cells(1, 2) & ":" & (ss.Cells(1, 3) + x)), "my_Procedure"
Adeel
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: TimeValue issue

Post by HansV »

Cell C1 contains 55.
x is a random value between 5 and 10.
So ss.Cells(1, 3) + x will be a value between 60 and 65. But the number of seconds should not exceed 59, hence the error.

Workaround #1: change the value of C1 to 49.
ss.Cells(1, 3) + x will then be between 54 and 59, which is valid.

Workaround #2: leave C1 unchanged, but change

x = Evaluate("randbetween(5,10)")

to

x = Evaluate("randbetween(0,4)")

ss.Cells(1, 3) + x will then be between 55 and 59, which is also valid.
Best wishes,
Hans

adeel1
3StarLounger
Posts: 264
Joined: 04 Oct 2017, 15:47

Re: TimeValue issue

Post by adeel1 »

many thx :clapping: :clapping: :clapping:

I have to work around this now how could I mange this. at least you put me on way :thankyou: :thankyou:

Adeel

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: TimeValue issue

Post by HansV »

I gave you two different ways to make it work...
Best wishes,
Hans

adeel1
3StarLounger
Posts: 264
Joined: 04 Oct 2017, 15:47

Re: TimeValue issue

Post by adeel1 »

yes, many thx issue resolved :thankyou: :thankyou: :thankyou: :thankyou: