How to keep ONKey's macro on Worksheet Selection Change Event

M

mikeburg

Using the following VBA code I get an error message "The macr
"C:\data\MSExcel\statement.xls'!JumpToA14' cannot be found.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Range("$B9:$C$9"), Range(Target.Address)
Is Nothing Then
'To turn on enter key macro
Application.OnKey "~", "JumpToA14"
Application.OnKey "{Enter}", "JumpToA14"
'To turn off enter key macro
Else
Application.OnKey "~"
Application.OnKey "{Enter}"
End If
End Sub

Private Sub JumpToA14()
'This line seems to work better Range("A14").Activate
Application.Goto Reference:=Range("A14")
End Sub

It works great if I put the Private Sub JumpToA14() in Module 1. Doe
anybody know how I can make it work by keeping both subs unde
Worksheet selection change event? (I really want the OnKey on th
Worksheet selection change event)

Thanks a million, Mikebur
 
J

Jim Thomlinson

The procedure referenced by the OnKey function must reside in a module. There
is no way around it.

FYI... Target and Range(Target.Address) are exactly the same thing. They
both are range objects.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top