Recursive call on the worksheet change in VBA

北慕城南 提交于 2020-01-04 06:16:27

问题


I have created the workbook with multiple sheet, i am trying to use WorkSheet_Change on Sheet1, i.e. something change on sheet1 is getting copied to sheet2. Similarly if anything change to Sheet2 i want to make similiar change on Sheet1 as well.

On doing so there is recursive call on both sheet please let me know how i can avoid this.


回答1:


you should disable events when calling your macro:

Sub Donot_Fire_Events()
    Application.EnableEvents = False
    ' Coding to skip these events
    Application.EnableEvents = True
End Sub



回答2:


Put a new global variable in a Module and call it bAutoUpdating As Boolean for example.

When the _Change code runs it should set this to true. Also any change routine should not fire if this is true. At the end of each _Change routine set back to bAutoUpdating = false



来源:https://stackoverflow.com/questions/6911880/recursive-call-on-the-worksheet-change-in-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!