Private sub worksheet_change (byval target as range)
Dim irow as integer
Irow = target. Row
Application. enableevents = false
Cells (irow, 3) = cells (irow, 3) + cells (irow, 2)
Application. enableevents = true
End sub
The purpose of this program is to input a new number in B2, C2 will display the new number entered in B2 plus the original number of C2 on C2.
If the application. enableevents = false program is added to it, the execution is fine.
Now add "'" before application. enableevents = false and application. enableevents = true (the following code ).
The purpose of adding "'" before the program is to convert the text after "'" into the description text. When the program is executed, the description text is skipped and the description text content is not executed.
After the "'" symbol is added before the program, the text turns green.
When you execute the second program, you will find that C2 will not present the results as you requested.
This is the so-called chain reaction of events.
Private sub worksheet_change (byval target as range)
Dim irow as integer
Irow = target. Row
'Application. enableevents = false
Cells (irow, 3) = cells (irow, 3) + cells (irow, 2)
'Application. enableevents = true
End sub
Another example is:
This example disables the event before saving the file so that the beforesave event cannot be triggered.
Application. enableevents = false
Activeworkbook. Save
Application. enableevents = true