Event doesn't fire

F

Frank Xia

Hi,
I am trying a simple worksheet change event as following:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
MsgBox ("ok")
End sub

but it does not fire and I can not the msgbox shown up. Is there any
condition apply to this event?

Any help appreciated!
 
G

Gary''s Student

You code works fine, but must be put in worksheet code.

Right-click any tab
Select view code
Enter your code
 
C

Chip Pearson

Frank,

Is the code in the ThisWorkbook code module? It must be in that
module, not a regular code module, for the code to work. Also,
ensure that Application.EnableEvents is True. In the VBA Editor,
press CTRL+G to display the Immediate window, and type the
following and press Enter

Application.EnableEvents = True


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
C

Chip Pearson

Chip Pearson said:
Is the code in the ThisWorkbook code module?

This is miswritten. The code must be in a sheet module, not the
ThisWorkbook module.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
K

Kevin Vaughn

Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox "ok"
End Sub
Worked for me. I wonder why yours says Excel.range and mine just says range?
 
F

Frank Xia

Thanks a lot! This helps and I learned!

Gary''s Student said:
You code works fine, but must be put in worksheet code.

Right-click any tab
Select view code
Enter your code
 
F

Frank Xia

Thank you very much! It helped!

Chip Pearson said:
Frank,

Is the code in the ThisWorkbook code module? It must be in that
module, not a regular code module, for the code to work. Also,
ensure that Application.EnableEvents is True. In the VBA Editor,
press CTRL+G to display the Immediate window, and type the
following and press Enter

Application.EnableEvents = True


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Top