VBA Sheet Change Event

I am trying to use a worksheet change event in Excel VBA, but it does not work.

From what I'm compiling, it’s easy enough to define the “Worksheet_Change” control function, as I did 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 

The problem is that I don’t know exactly where I should determine it. I just put it in "module1", which was automatically generated when I made my first macro. It's right? I am new to VBA, so I don't know about it yet.

+7
source share
1 answer

You need to put it on the sheet to which it relates. 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.

enter image description here

+11
source

Source: https://habr.com/ru/post/915041/


All Articles