我有一个奇怪的bug,我似乎不能解决它,我有以下代码:
Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox "change"
End Sub这应该会在每次单元格更改时在我的工作表上触发,但是直到我单击返回到开发人员模式,它才会触发msgbox。只有当我点击开发者模式时,它才会触发x次我在工作表上所做的更改。
我在一张新的工作表上试了试,它工作得很好。有没有什么东西会阻止细胞功能的改变正常工作?我不明白为什么它不能运行,直到我进入我的开发者页面。据我所知,Appliation.EnableEvents设置为True。
只是为了澄清一下:这个函数只在我点击开发者模式时运行。感觉就像我一进入开发人员模式,它就会先排队,然后触发。
发布于 2021-09-27 02:08:49
右键单击您的工作表并粘贴以下代码示例。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("A1:C10")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
' Display a message when one of the designated cells has been
' changed.
' Place your code here.
MsgBox "Cell " & Target.Address & " has changed."
End If
End Sub请记住,这是表单代码,而不是模块代码。
https://stackoverflow.com/questions/69338908
复制相似问题