move cursor

P

Peter

Hi,

Is it possible that, when you hit the enter button, the cursor moves to a
cell specified by me?
For instance:
A1 ==>"enter" ==>G4
 
T

Tom Ogilvy

No matter where the activecell is, if the user hits enter, you want to go to
G4?
 
P

Peter

No, the activecell is specified.
It's like the textbox- taborder in a userform, you know what i mean?
 
T

Tom Ogilvy

Select the cells in the order you want to travel through them. Then leave
them selected.
 
T

Tom Ogilvy

Just to clarify.
Use the mouse and the control key to select the cells in the order you want
to nagivate through them (so that all the cells of interest are selected).
then leave them selected.

Now use the enter/return key to travel through them.
 
P

Peter

Hi again Tom,

That was something i knew, but it is not what i meant.
I'm going to try to give you an example of what i want.

in a vba code:
A1 => G5 => E3 => K10 => F2
when A1 is selected and enter is hit move to cell G5
when E3 is selected and enter is hit move to cell K10
when................and so on

The starting cell is a single selected cell, the end cel is the next cell
that has been written in the code.

I don't want all the cells selected at the same time, i'm just looking for a
taborder to move from one cell to another.

Regards,
Peter
 
T

Tom Ogilvy

Just use the selectionchange event to record (update a static variable) the
last activecell (it already tells you the cell selected). Test if the last
active cell was one of the ones you are interested in, and if so, then
change the selection to the next cell you want selected. Make sure you
disable events so you don't go into an endless loop.

so as an example, right click on the sheet tab and select view code. Put in
code like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static oldCell As Range
If Not oldCell Is Nothing Then
Debug.Print oldCell.Address
Select Case oldCell.Address(0, 0)
'A1 => G5 => E3 => K10 => F2
Case "A1": sStr = "G5"
Case "G5": sStr = "E3"
Case "E3": sStr = "K10"
Case "K10": sStr = "F2"
Case "F2": sStr = "A1"
Case Else: sStr = ""
End Select
If sStr <> "" Then
Application.EnableEvents = False
Range(sStr).Select
Application.EnableEvents = True
End If
End If
Set oldCell = ActiveCell

End Sub
 

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