Control Cursor movement with Tab

G

Guest

I have created a form with Excel. I need to know if I can plan the path of
the cursor so that when the user presses Tab, the cursor goes to a
predetermined cell (Or group of cells) rather than just move logically to the
next unprotected cell.

Thank you
 
G

Gord Dibben

Surely can.

Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Address
Case "$C$2"
Range("C5").Select
Case "$C$5"
Range("E2").Select
Case "$E$2"
Range("E5").Select
End Select
End Sub

Just keep adding cases and ranges.


Gord
 
G

Guest

Gord,

I use Office XP (Excel XP), I tried both of the methods detailed in this
thread and neither one worked for me. I tried the "case select" with
protection on and I tried the "named range" with protection both on and off.
What am I doing wrong?
 
G

Gord Dibben

Only the one method outlined at Bob's site uses sheet protection and unlocked
cells.

The named range method does need sheet protection.

The Case Select method which is now working for you does not use sheet
protection either.

Gord
 
G

Guest

Gord,

Thanks for the quick reply. Now that I know I'm not supposed to use
Worksheet Protection I was all jazzed about finally seeing this work. But...
nothing seems to be controlling the movement of the cursor. Here is my code:

Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Address
Case "$E$5"
Range("E12").Select
Case "$E$12"
Range("E14").Select
Case "$E$14"
Range("E16").Select
Case "$E$16"
Range("E18").Select
Case "$E$18"
Range("E20").Select
Case "$E$20"
Range("E22").Select
Case "$E$22"
Range("O12").Select
Case "$O$12"
Range("O14").Select
Case "$O$14"
Range("O16").Select
Case "$O$16"
Range("O18").Select
Case "$O$18"
Range("V12").Select
Case "$V$12"
Range("V14").Select
Case "$V$14"
Range("V16").Select
Case "$V$16"
Range("V18").Select
Case "$V$18"
Range("R12").Select
Case "$R$12"
Range("R14").Select
Case "$R$14"
Range("R16").Select
Case "$R$16"
Range("R18").Select
Case "$R$18"
Range("X12").Select
Case "$X$12"
Range("X14").Select
Case "$X$14"
Range("X16").Select
Case "$X$16"
Range("X18").Select
Case "$X$18"
Range("E5").Select
End Select
End Sub

One thing I noticed was the Private Sub naming. By default my Visio Studio
provided "Worksheet_SelectionChange(ByVal Target As Range)", but your example
uses "Worksheet_Change". Have I introduced an error? And where can I read
about the function Target.Address?

Thanks again for your assistance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top