Is this expected behavior?

M

maweilian

I have several worksheets in a single workbook and I have several VBA
functions used within the workbook that use arguments from different sheets
in the workbook. When the entire workbook recalculates, it appears as if the
VBA macros run several times, even if used only once in the workbook. For
instance, one VBA function displays an error box if certain parameters are
outside of an acceptable range, which is what it is supposed to do. However,
when the workbook recalculates, the error box pops up 4-5 times saying the
arguments are incorrect, but after the boxes are closed everything is
calculated correctly. The function is working correctly, but it is as if
the function ran 4-5 times before the correct arguments where finally passed
to the function.

Is this expected behavior? How can I stop this from happening?

Thanks,

Will
 
J

JLGWhiz

Sounds like you are triggering a Worksheet_Change event, or some change
event. There is more than one way to fix the problem, but without
definitely tying it down to the exact cause and seeing the relevant code, I
would not pretend to offer a soloution.
 
J

Jacob Skaria

Do you have a worksheet change event? If so add additional code to disable
and enable the events...

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False

'your code

Application.EnableEvents = True
End Sub

If this post helps click Yes
 

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

Top