Solved

Tab functionality in Excel

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

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 80

Expert Comment

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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MsgBox 2 38
Determine Range to Select 5 35
Access 2013 combo box not working 3 27
Add and format columns in vb6 7 26
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

744 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

11 Experts available now in Live!

Get 1:1 Help Now