Socrates said:
If you check the Move selection on Return checkbox in Preferences/Edit and
set the direction dropdown to "down", both the Return key and the Enter key
cause the selection to move down.
That's exactly what I want but it's not working that way. The pref affects
ONLY the Return key. I'm not at my Mac right now so I can't test but, if I
remember correctly, the pref does work that way if protection is OFF.
However, when protection is ON, the Enter key ALWAYS moves the selection to
the right.
Yup, that's right - protecting the sheet makes the Enter key stop
changing the selection. It appears to be design behavior - at least it's
worked that way since XL01, but I've asked MacBU why it works that way.
I'll post back if I get an answer...
However, here's a workaround I took from a previous project. It's not
particularly robust - while it works like the Return key for a single
cell selection or for a single multiple-cell selection, it doesn't work
for multiple areas within a selection, though it shouldn't be hard to
modify it.
The protection state of the worksheet doesn't affect the macros'
operation.
Save this in a new workbook as an add-in, or download my example add-in
at
ftp://ftp.mcgimpsey.com/excel/moveright.xla
and install it (Tools/Add-ins...).
Put these in the ThisWorkbook code module:
Private Sub Workbook_Open()
Application.OnKey "{Enter}", "MoveRight"
Application.OnKey "+{Enter}", "MoveLeft"
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnKey "{Enter}", ""
Application.OnKey "+{Enter}", ""
End Sub
Put these in a regular code module:
Public Sub MoveRight()
If TypeOf Selection Is Range Then
With Selection
If .Count = 1 Then
If .Column <> .Parent.Columns.Count Then _
.Offset(0, 1).Activate
Else
If ActiveCell.Column < .Cells(.Count).Column Then
ActiveCell.Offset(, 1).Activate
Else
If ActiveCell.Row < .Cells(.Count).Row Then
ActiveCell.Offset(1, _
1 - .Columns.Count).Activate
Else
.Cells(1, 1).Activate
End If
End If
End If
End With
End If
End Sub
Public Sub MoveLeft()
If TypeOf Selection Is Range Then
With Selection
If .Count = 1 Then
If .Column <> 1 Then _
.Offset(0, -1).Activate
Else
If ActiveCell.Column > .Column Then
ActiveCell.Offset(, -1).Activate
Else
If ActiveCell.Row = .Row Then
.Cells(.Count).Activate
Else
ActiveCell.Offset(-1, _
.Columns.Count - 1).Activate
End If
End If
End If
End With
End If
End Sub