+ Reply to Thread
Results 1 to 4 of 4

Differentiate keypresses in Worksheet_SelectionChange event

  1. #1
    Registered User
    Join Date
    11-13-2010
    Location
    Springfield, IL
    MS-Off Ver
    Excel 2007
    Posts
    36

    Differentiate keypresses in Worksheet_SelectionChange event

    I have several pieces of code setup in a Worksheet_SelectionChange event. I've run into a situation where I must be able to have the event track whether a cell was entered by using either the enter key or the down arrow. I'm not sure if this is even possible. Unfortunately, there is no such thing as a Worksheet_KeyUp event.
    I would greatly appreciate any ideas.

    Thank you!

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Differentiate keypresses in Worksheet_SelectionChange event

    First things I have to ask are:
    1. Why?
    2. What if the user selects a cell with the mouse?
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    11-13-2010
    Location
    Springfield, IL
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Differentiate keypresses in Worksheet_SelectionChange event

    1) I have text boxes placed on my worksheet and code in place to activate the text boxes when worksheet-selectionchange event detects when certain cells are selected. Code is also in place to prevent entry and immediate exit when the enter key is pressed to enter the txt box.
    2) mouse clicks pose no problems so far.

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Differentiate keypresses in Worksheet_SelectionChange event

    Well, the only thing I can think of would be to set a low level keyboard hook using the Windows API, as it's the only way (other than timers, which don't make sense here) to be able to run code while in edit mode, which you need to do to trap the user entering data and switching cells when pressing enter or tab or an arrow key. Not for the faint hearted though since if it goes wrong it will likely crash your application completely.
    For the record, it sounds to me as though you would be better off with a userform (or a database app).

+ 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