View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Anthony[_15_] Anthony[_15_] is offline
external usenet poster
 
Posts: 18
Default Working with times - Bug?

The a1 and b1 was just to show you that I was using the values of the cells
and not my actual code, it was an easy to read version of what I have.

The cells contain a time formatted as [h]:mm. These times are derived from
other information in the worksheet.

They are then checked to see if they are the same and then perform the
required action.

values in K and L are calculations which return a time value.

If (Worksheets("settings").Range("K21").Value =
Worksheets("settings").Range("J21").Value) Then

Application.EnableEvents = False

Worksheets(Me.tbState.Text & "
workplan").Cells(CInt(Me.tbSelectedLine.Text), "A").Interior.Color = vbRed
'show delay
Worksheets(Me.tbState.Text & "
workplan").Cells(CInt(Me.tbSelectedLine.Text), "A").Value = _
Worksheets("duties - " &
Me.tbState.Text).Cells(CInt(Me.tbSelectedLine.Text ), "A").Value & _
" (" &
time_to_text((Worksheets("settings").Range("L21"). Value - _
Worksheets("settings").Range("K21").Value),
2) & ")"


Application.EnableEvents = True

Else

Application.EnableEvents = False

Worksheets(Me.tbState.Text & "
workplan").Cells(CInt(Me.tbSelectedLine.Text), "A").Interior.Color = vbWhite
'reset value
Worksheets(Me.tbState.Text & "
workplan").Cells(CInt(Me.tbSelectedLine.Text), "A").Value = _
Worksheets("duties - " &
Me.tbState.Text).Cells(CInt(Me.tbSelectedLine.Text ), "A").Value

Application.EnableEvents = True

End If

'calculate new totals
Calculate_office_totals (Me.tbState.Text)

This is a small section of the code.

Thank you for your reply.

Regards

Anthony
"Ron Rosenfeld" wrote in message
...
On Sun, 16 Aug 2009 01:05:23 +0100, "Anthony"

wrote:

Hi,

I am using excel 07 in compatibility mode, due to the compay i work for
only
have excel 03.

I have come across what seems to be a bug in excel vba or how it uses time
in calculations;

I wondered if anyone has had similar issues;

Cells formatted [h]:mm

A1 = 45:30
B1 = 45:30

in vba i had ;

if(a1= b1) then

do some stuff to sheets

else

do something else

end if

This always went to the else section of the statement.

I even used a msgbox to display the decimal values to view what the code
was
seeing and they were exactly the same.

To get this to work I had to do the calculation on the worksheet and then
just test the cell value.


Anyone any idea? is it a bug or just something I have done wrong?

regards


Anthony


I cannot reproduce your results.

It would be helpful if you posted the actual code you are using, as well
as
information as to the actual contents of a1 and b1.

As written, your vba code is not referring to any cells. So either you
have
initialized them previously, or they are merely undeclared variables.

If they are, in fact, undeclared empty variables, I'm surprised at your
results. I would have expected the code to always "do some stuff" as the
comparison should evaluate to True.

A handy option in writing good code is to require variable declarations.
See
Tools/Options/Editor/Code settings. This precedes VBA code with the
Option
Explicit statement.
--ron