Solved

Tab functionality in Excel

Posted on 2004-09-10
5
155 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now