Controlling cursor w/ macro

W

WLMPilot

I need to control the position of the cursor in Excel 2002, when a person
hits the ENTER key. This is a form that is being filled out. I need to
first place the cursor in A3 when the worksheet becomes active. The movement
after the proceeds as follows:

A3, A4, A5, C4, D4, E4,....(Skip J4)...K4

As for A3-A5, only one of those cells will contain a value, in this case an
"X". So if user presses the ENTER key while in A3 and advances to A4 and
inputs an "X", I can skip A5. Same goes for an "X" in A3, I can skip A4 & A5.

If you can give me this part, I can add the remaining code (I hope).

Thanks,
Les
 
J

Jim Thomlinson

Give this code a whirl. It needs to be pasted directly into the sheet so
right click the tab you want and select view code. Paste the following

Private rngLastCell As Range

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrorHandler
Application.EnableEvents = False

If Not Intersect(Target, Range("A3:A5")) Is Nothing _
And UCase(Target.Value) = "X" Then Set rngLastCell = Range("A5")

ErrorHandler:
Application.EnableEvents = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

On Error GoTo ErrorHandler
If rngLastCell Is Nothing Then Set rngLastCell = Range("A3")

Application.EnableEvents = False
Select Case rngLastCell.Address
Case "$A$3"
Range("A4").Select
Case "$A$4"
Range("A5").Select
Case "$A$5"
Range("C4").Select
Case "$C$4"
Range("d4").Select
Case "$D$4"
Range("E4").Select
Case "$E$4"
Range("K4").Select
Case "$K$4"
Range("A3").Select
End Select
Set rngLastCell = ActiveCell
ErrorHandler:
Application.EnableEvents = True
End Sub
 
W

WLMPilot

Thanks for the infor. I am confused (ignorant) about a couple of things you
have:
1) You show "Private rngLastCell As Range" before the subroutine. What does
this do?
2) Not sure what you mean by right click the tab. Are you referring to the
worksheet tab at the bottom?

Les

Thanks again?
 
J

Jim Thomlinson

That is a variable that is in scope fer every procedure in the sheet in which
it is placed. Additionally it is persistent and does not loose it's value
when a procedure ends.

As for the second part, yes I am refering to the work sheet tab. The code
needs to be embeded right in the sheet...
 
W

WLMPilot

Thanks for your help. I am not at the point that I am ready to insert it and
test it, but I am sure it will be what I need.

Thanks,
Les
 

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