PDA

View Full Version : [SOLVED] No response to change event



Elly
05-01-2017, 04:58 AM
I am learning about event procedures. I cannot understand why the following procedure is not activated when a value is entered in a cell and the cell value is then changed.


Private Sub Worksheet_Change(ByVal Target AS Range)
Dim Col As Long
Dim Row As Long

Co = Target.Column
Row = Target.Row

MsgBox Col
MsgBox Row

End Sub

I am using Excel 2016 with Windows 10.

The workbook Basic Test is attached.

mana
05-01-2017, 05:34 AM
Try executing this code


application.enableevents=true




Or excel application quit & restart

mdmackillop
05-01-2017, 05:37 AM
Nothing wrong with your example. Make sure events are enabled

Sub Enables()
Application.EnableEvents = True
End Sub

Elly
05-02-2017, 03:07 AM
Thanks Guys. I added 'Application.EnableEvents = True ' to the Workbook_Open procedure and it cleared the problem.

mdmackillop
05-02-2017, 04:06 AM
In Event code, you may want to set events to False to prevent looping. Use something like this to ensure in the case of an error that Events are re-enabled.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Col As Long
Dim Row As Long

Application.EnableEvents = False
On Error GoTo Exits

Co = Target.Column
Row = Target.Row

MsgBox Col
MsgBox Row
Exits:
Application.EnableEvents = True
End Sub