+ Reply to Thread
Results 1 to 3 of 3

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

  1. #1
    Forum Contributor
    Join Date
    06-23-2005
    Posts
    253

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

    Using the following VBA code I get an error message "The macro "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. Does anybody know how I can make it work by keeping both subs under Worksheet selection change event? (I really want the OnKey on the Worksheet selection change event)

    Thanks a million, Mikeburg

  2. #2
    Jim Thomlinson
    Guest

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

    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.
    --
    HTH...

    Jim Thomlinson


    "mikeburg" wrote:

    >
    > Using the following VBA code I get an error message "The macro
    > "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. Does
    > anybody know how I can make it work by keeping both subs under
    > Worksheet selection change event? (I really want the OnKey on the
    > Worksheet selection change event)
    >
    > Thanks a million, Mikeburg
    >
    >
    > --
    > mikeburg
    > ------------------------------------------------------------------------
    > mikeburg's Profile: http://www.excelforum.com/member.php...o&userid=24581
    > View this thread: http://www.excelforum.com/showthread...hreadid=400992
    >
    >


  3. #3
    Forum Contributor
    Join Date
    06-23-2005
    Posts
    253
    Thanks a million. I'm still learning.

    mikeburg

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1