Move to SELECTED Cells

D

Danny

I got this macro from this newsgroup (thank you) that
enables the user to move to selected cells by filling up
the cell or use the tab key:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$2" Then Range("G4").Select
If Target.Address = "$G$4" Then Range("C6").Select
If Target.Address = "$C$6" Then Range("E6").Select
'Etc, etc, etc...
End Sub


However, if the active cells are already filled up and the
operator uses the ENTER key to move to the next cell, it
doesn't work. Let's say the active cell is C2 (previously
filled-up). If you press enter, the active cell will be C3
instead of G4.

Please help.
 
T

Tom Ogilvy

It doesn't have anything to do with whether the cell contains an entry or
not. The change event only fires when the user finishes editing a cell.
The can make a change or not - but if they are in edit mode and leave it,
then the change event fires. Other than that, your macro would not have any
effect.

If you want the kind of control you state, you would also need to use the
selectionchange event and use a static variable to store the last selection,
then if it meets one of your criteria, move the selection to the
appropropriate cell (possibly disabling events so you don't get a recursive
call).

Have you tried unlocking the cells where you want entries and protecting the
sheet. If that won't give you the order you want, then perhaps you need to
think about redesigning the layout of your sheet.
 
D

Danny

I unlocked all selected cells and protected the sheet. I
am just wondering that if I use the TAB key, it works. It
also works when you EDIT a cell and press ENTER. Can you
edit my macro so if I press ENTER, it will move to the
next SELECTED cell regardless if I edit the cell or not
(like pressing the TAB key to move to the next selected
cell)?

Thanks in advance.
 
T

Tom Ogilvy

Private Sub Worksheet_Change(ByVal Target As Range)
Application.MoveAfterReturnDirection = xlToLeft
me.EnableSelection = xlUnlockedCells
If Target.Address = "$C$2" Then Range("G4").Select
If Target.Address = "$G$4" Then Range("C6").Select
If Target.Address = "$C$6" Then Range("E6").Select
'Etc, etc, etc...
End Sub
 
D

Danny

Tom,
Thank you for your response. With the macro below, after
pressing enter, it won't move to the next selected cell
unless you edit the cell.
Regards,
Danny
 
D

Danny

Tom,
I'm sorry, when you press enter, it moves to the left, NOT
to the NEXT SELECTED Cells.
Thanks,
Danny
 
T

Tom Ogilvy

I unlocked all selected cells and protected the sheet. I
am just wondering that if I use the TAB key, it works. It
also works when you EDIT a cell and press ENTER.

The two commands I added will make the enter key work like the tab key.
That is what you asked. It doesn't fire (i.e. the settings are not made)
until you edit one cell. You could put it (those commands, appropriately
modified) in the sheet activate event or the workbook open event.
 
D

Danny

Tom,

The glitz was my mistake. C2 is unlocked, however, I
didn't realize that when I was making the form I merged C2
and C3 (locked). After unlocking the merged cells, the two
commands you provided works perfectly.

Thank you so much for your time and patience.

Have a great weekend.

Regards,
Danny
 
Top