+ Reply to Thread
Results 1 to 3 of 3

How to prevent SelectionChange event firing before Change event?

  1. #1
    Registered User
    Join Date
    05-20-2012
    Location
    Mexico
    MS-Off Ver
    Excel 2002
    Posts
    12

    How to prevent SelectionChange event firing before Change event?

    I'm using selection change events to control cursor movement on tab or return.


    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    '
    If ActiveCell.Address = "$C$1" Then
    Application.OnKey "{TAB}", "ToC9"
    Application.OnKey "~", "ToC9"
    End If
    '
    If ActiveCell.Address = "$C$9" Then
    Application.OnKey "{TAB}", "ToE9"
    Application.OnKey "~", "ToE9"
    End If
    '
    End Sub
    '
    Sub ToC9()
    Sheets("Calculator").Range("C9").Select
    End Sub
    '
    Sub ToE9()
    Sheets("Calculator").Range("E9").Select
    End Sub
    '

    It works fine. But I also want to run a WorkSheet_Change event triggered by the second cell $C$9, that results in $C$1 being selected.

    Private Sub Worksheet_Change(ByVal Target As Range)
    '
    If Target.Address = "$C$9" Then
    Call ToC1
    End If
    '
    End Sub
    '
    Sub ToC1()
    Sheets("Calculator").Range("C1").Select
    End Sub
    '

    The idea is that when tabbing through the cells, if C9 is no change then E9 is selected but if C9 has changed then C1 is selected. At the moment if C9 changes, the focus jumps to E9 and then to C1, ie the SelectionChange event is firing before the Change event. Any ideas as to a solution? My many thanks in advance.

  2. #2
    Forum Guru Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,286

    Re: How to prevent SelectionChange event firing before Change event?

    If it arrives at C1, even via E9, what is the problem?

  3. #3
    Registered User
    Join Date
    05-20-2012
    Location
    Mexico
    MS-Off Ver
    Excel 2002
    Posts
    12

    Re: How to prevent SelectionChange event firing before Change event?

    Hi Bob,

    Thanks for your response. In my description I stripped out what I believed to be unnecessary details. The C9 Change event calls a message box containing info about C9 with an OK button after which C1 is selected. As things are, E9 is being highlighted / selected whilst the message box is displayed, creating the impression that the info is about E9.

+ 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