Using a time value in a macro

  • Thread starter Thread starter Patrick Simonds
  • Start date Start date
P

Patrick Simonds

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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top