ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Is this expected behavior? (https://www.excelbanter.com/excel-programming/430519-expected-behavior.html)

maweilian

Is this expected behavior?
 
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

-----------------------------------------------------------------------------
Less Spam Better enjoyable experience
Visit : news://spacesst.com

JLGWhiz[_2_]

Is this expected behavior?
 
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.


"maweilian" wrote in message
...
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




-----------------------------------------------------------------------------
Less Spam Better enjoyable experience
Visit : news://spacesst.com

Jacob Skaria

Is this expected behavior?
 
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
---------------
Jacob Skaria


"maweilian" wrote:

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


-----------------------------------------------------------------------------
Less Spam Better enjoyable experience
Visit : news://spacesst.com


All times are GMT +1. The time now is 10:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com