Weird Behaviour Function not invoked

S

sharon

I see a weird behaviour in VBA code, not always but from time to time.
I've seen this in more than one workbook, so I'd like to know how to fix it.

Having (line numbers are just for explanation purposes)
001 For each cel in range("rTotal")
002 cel.offset(0,2)="x"
003 Next
.....
.....
100 Function anYthing( xLOL as string) as string
101 Application.Volatile True
102 Sheets("STAT").Select
103 Range("lVAL").Select
104 Sw = Sw + 1
105 If Sw > 250 Then
106 MsgBox ("Times: " + Str(Sw))
107 End If
108 anYthing="anything"
109 Function End


While normal flow would be looping through steps 1 -2 -3 some times I can
see (while debugging) that flow is 1 - 2 - and looping (several times) steps
103 104 - 100, which is a function actually not invoked.
Eventually it goes back to 3-2-1

Any clue?

Sharon
 
J

JLGWhiz

I have noticed similar behavior when debugging. Although I could not
immediately see a reason, I have come to believe that it is a logic protocol
built into VBA that, in certain circumstances, VBA will check to see if there
is another part of the code that needs to do things like recalculate, run a
before event code, etc. It is the only explanation I could come up with.
 
S

sharon

So far, is any MVP or regular user who could put some light on this issue?

A simple strX=Cel causes a weird jump to the un-invoked Function, doing just
3 steps on it (several times) and exiting after doing a sentence like
Range("F2").Select when there are 50 sentences after this one and before the
End Function

????

TIA,

Sharon
 

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

Similar Threads


Top