View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Working with times - Bug?

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