Solved

Tab functionality in Excel

Posted on 2004-09-10
5
159 Views
Last Modified: 2010-05-02
I have a custom application developed in Excel using VBA and macros.  Users will be doing data entry using this template.  I would like to automate the cell location following a tab out of a specific column.  Is there a way to capture the tab event only for a specific column?
0
Comment
Question by:corduroy9
5 Comments
 
LVL 1

Expert Comment

by:macaulish
ID: 12030646
What exactly are you trying to do?  I don’t think there’s a way to trap the tab key event but I may be able to devise a workaround if I know more details.
0
 
LVL 2

Expert Comment

by:pittbb
ID: 12031204
You don't need to use any code at all in Excel 11.  (What version of excel are you using?).  Unlock whatever cells you want to be tab stops.  (cntrl + 1 - protection tab - uncheck "locked").  Then from tools - protection - protect sheet - allow all users of this worksheet to... - uncheck "Select locked cells."  Then the tabs should only go to the cells that you unlocked.  The are all locked by default - which does nothing unless the protection is turned on.  I believe this will give you the functionality you are looking for.  Not sure if the menus, functionality, etc is the same in previous versions, but if the funcitonality is there (I think it is), it would be a similar set of steps.

Hope this helps...
0
 
LVL 81

Accepted Solution

by:
byundt earned 100 total points
ID: 12036733
You can trap the tab key using the Application.OnKey method. Here are some subs that go into the code pane for the worksheet for this purpose. When Sheet1 is activated, the tab key is trapped by the TabNext sub. If the active cell is in column A, then the Select Case determines which cell to go to next. When Sheet1 is deactivated, the tab key is restored to its normal function.

Private Sub Worksheet_Activate()
Application.OnKey "{TAB}", "Sheet1.TabNext"    'Trap the tab key when this worksheet is active
End Sub

Private Sub Worksheet_Deactivate()
Application.OnKey "{TAB}", ""   'Restore default action of tab key when sheet deactivated
End Sub

Sub TabNext()
If Intersect(ActiveCell, Columns("A")) Is Nothing Then Exit Sub
Select Case ActiveCell.Row  'Create the Tab order as follows
Case 2
    Range("A5").Select
Case 5
    Range("A8").Select
Case 8
    Range("A2").Select
End Select
End Sub
0
 
LVL 2

Author Comment

by:corduroy9
ID: 12079168
Sorry this took so long - I've been traveling.

Thanks Bryundt - that seems to be working for me!  Pittbb, that solution may work as well, but the programmatic solution is really what I was looking for.  
0
 
LVL 81

Expert Comment

by:byundt
ID: 12079490
corduroy9,
Thanks for the grade!
Brad
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question