VBA工作表更改事件 [英] VBA Worksheet Change Event
问题描述
我正试图在Excel VBA中使用工作表更改事件,但似乎不起作用。
I am trying to use the Worksheet Change Event in Excel VBA, but it doesn't seem to work.
从我收集的内容中,定义处理函数Worksheet_Change,就像我在这里所做的那样:
From what I gather, it is enough to just define the handling function "Worksheet_Change" as I have done here:
Private Sub Worksheet_Change(ByVal Target As Range)
Range("J1").Select
If Target.Address = "$J$1" And ActiveCell.Value = 1 Then
Range("B1").Select
Dim c As Integer
c = ActiveCell.Value
c = c + 1
ActiveCell.Value = c
End If
End Sub
问题是我不确定我应该在哪里定义它。我刚刚把它放在module1中,当我做了我的第一个宏时自动生成。它是否正确?我对VBA很新,所以我还不太了解。
The problem is that I am not sure exactly where I am supposed to define it. I have just put it in "module1" which was automatically generated when I made my first macro. Is this correct? I am quite new to VBA, so I don't know much about it yet.
推荐答案
你需要把它放在适用的表格。换句话说,如果要捕获Sheet1上的更改事件,请在VBA编辑器中将其放在VBAProject(Book_Name)> Microsoft Excel Objects> Sheet1中。
You need to put it in the sheet that it applies to. In other words, if you want to capture change events on Sheet1, in the VBA editor, you need to put it in VBAProject (Book_Name) > Microsoft Excel Objects > Sheet1.
这篇关于VBA工作表更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!