ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using a time value in a macro (https://www.excelbanter.com/excel-programming/321212-using-time-value-macro.html)

Patrick Simonds

Using a time value in a macro
 
In the place of the 30 in the formula below, I need to enter the time value
of 00:30 but the macro errors out as soon as I do this.

ElseIf Cells(1, 13).Value = 30 Then
OptionButton2.Value = Tue



Tom Ogilvy

Using a time value in a macro
 
You migh run into problems. For example from the immediate window:

? activeCell = timeserial(0,30,0)
False
? activeCell.Text
0:30:00

Depending on how your value gets into the cell, it may be exactly 30 minutes
or it could be a fraction of a second off and still show as 30 minutes. you
might try

if Abs(TimeSerial(0,30,0)-Cells(1,13).Value) < TimeSerial(0,0,1) then

You can change the granularity of the difference you are willing to accept.

so back to the immediate window:
? Abs(TimeSerial(0,30,0)-ActiveCell.Value) < TimeSerial(0,0,1)
True

--
Regards,
Tom Ogilvy


"Tim Williams" <saxifrax at pacbell dot net wrote in message
...
Try

ElseIf Cells(1, 13).Value = TimeSerial(0,30,0) Then


Tim

"Patrick Simonds" wrote in message
...
In the place of the 30 in the formula below, I need to enter the time

value
of 00:30 but the macro errors out as soon as I do this.

ElseIf Cells(1, 13).Value = 30 Then
OptionButton2.Value = Tue








All times are GMT +1. The time now is 07:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com