+ Reply to Thread
Results 1 to 14 of 14

How to detect if TAB key has been pressed?

  1. #1
    Registered User
    Join Date
    05-08-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    69

    How to detect if TAB key has been pressed?

    Hi guys,

    I'm trying to write a code that detects when the tab key has been pressed, and if it has, send an email, if it hasn't, kick you out and reset the cell. All of this is in Worksheet Change
    I have everything working except the tab key detection and could use some help on that.


    Please Login or Register  to view this content.
    Thanks!

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to detect if TAB key has been pressed?

    Hi bgreeson

    Play with this...

    In the Sheet Module
    Please Login or Register  to view this content.
    In a General Module
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    05-08-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    69

    Re: How to detect if TAB key has been pressed?

    John,

    Works fantastically! No further edits were needed Thanks so much for the help!

    Brad

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to detect if TAB key has been pressed?

    You're welcome...glad I could help. Thanks for the Rep.

  5. #5
    Registered User
    Join Date
    05-08-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    69

    Re: How to detect if TAB key has been pressed?

    If I want to do this for multiple UserForms, how would I do that? For instance:

    In Worksheet:
    Please Login or Register  to view this content.
    In General Module (all one module):
    Please Login or Register  to view this content.

    When I do that, it will bring up the wrong UserForms

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to detect if TAB key has been pressed?

    Hi Brad

    First go to the Immediate Window in VBA...type this Application.OnKey "{TAB}", press enter.

    Then try this Code
    Please Login or Register  to view this content.
    Last edited by jaslake; 01-10-2015 at 03:51 PM.

  7. #7
    Registered User
    Join Date
    05-08-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    69

    Re: How to detect if TAB key has been pressed?

    I get "Compile Error: Invalid use of property" and it highlights "Call DDA". My thoughts are that I need to use DDA.show rather than a call, but I could be wrong.

    I also tried to add multiple Modules, each with its own version of the first solution above, but that didn't work either.

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to detect if TAB key has been pressed?

    Hi Brad

    Try the Code in the attached...
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    05-08-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    69

    Re: How to detect if TAB key has been pressed?

    No luck. There's some more code that might be interfering. I'll attach the file here. The woman I am making this for isn't the best at excel. I'm trying to make it bulletproof so that the only way you can bring the UserForms up is by putting a date in the desired cells, and then pressing TAB (because having both ENTER and TAB "makes it too complex". The UserForm then send out an automated email using Outlook, for whomever's computer this is on, to the desired recipients. I've deleted the proprietary info.

    Architectural & Estimating Status Master (1) - Copy.xlsm

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to detect if TAB key has been pressed?

    Hi Bra

    So I understand...you want the UserForm to appear ONLY IF the TAB key is pressed?

  11. #11
    Registered User
    Join Date
    05-08-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    69

    Re: How to detect if TAB key has been pressed?

    Correct. I want to be able to enter a date (which is really just a number) into one of the 5 columns and have the corresponding UserForms "pop-up"/show only when TAB is pressed. If ENTER or clicked-out, do nothing. TAB should still be able to be pressed like normal in other cells.

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to detect if TAB key has been pressed?

    Hi Brad

    Let me look at it a bit further...no guarentees...

  13. #13
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to detect if TAB key has been pressed?

    Hi Brad

    I've adapted some Code from here to capture the Enter Key Press.
    http://www.experts-exchange.com/Soft..._27118905.html

    I will caution you, if you're going to modify the Code either run this procedure in Module 3
    Please Login or Register  to view this content.
    or select one of the Information Worksheets before entering VBA as the above Code is triggered upon Deactivation of the Status Worksheets.

    I don't pretend to understand what the Hook Keyboard Code is doing except to say the Code is monitoring all the Key Presses and if the Enter Key is pressed and the Target Cell is in one of the Five Columns, the User will get a message to use the TAB key.

  14. #14
    Registered User
    Join Date
    05-08-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    69

    Re: How to detect if TAB key has been pressed?

    Sorry for the delayed reply. Some unexpected life events happened for me.

    This is pretty complex. I'll look into it and try to figure it all out. Thanks for all the help, I really appreciate it it might be a week or two before I confirm or "deconfirm" anything

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Recognize ALT key Pressed
    By Steve in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-12-2006, 05:55 PM
  2. [SOLVED] What key was pressed?
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-30-2005, 05:05 AM
  3. Was Delete Key pressed?
    By HLong in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-05-2005, 06:05 PM
  4. how to detect mouse pressed(down) event for work sheet
    By chawla12amit in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2005, 12:15 PM
  5. how to detect mouse pressed(down) event for work sheet:color the cells
    By helpwithXL in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-18-2005, 12:06 PM

Tags for this Thread

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