Move selection after Enter Direction

T

Tonso

I have a macro that enables me to toggle between moving the selection
down, or to the right, after Enter.

Sub MoveAfterReturn()
If Application.MoveAfterReturnDirection = xlDown Then
Application.MoveAfterReturnDirection = xlToRight
Else
Application.MoveAfterReturnDirection = xlDown
End If
Application.ScreenUpdating = True
End Sub

This works good, but i would like to automate the application of the
macro in a particaular workbook by having it move "right" if the
active cell is in the range E4:M34. If not in that range, it would
move "Down".
How can i accomplish this?

Thank you so much,

Tonso
 
D

Dave Peterson

You can use a worksheet_Change event that is associated with a single worksheet.

If you want to try, you right click on the worksheet tab that should have this
behavior and paste this into the code module that appears:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count > 1 Then
Exit Sub 'single cell only!
End If

If Intersect(Target, Me.Range("e4:m34")) Is Nothing Then
'not in E4:M34, so...
'Application.MoveAfterReturnDirection = xlDown
Target.Cells(1).Offset(0, 1).Select
Else
'in E4:M34
'Application.MoveAfterReturnDirection = xlToRight
Target.Cells(1).Offset(1, 0).Select
End If

End Sub

Notice that the application setting is commented out. This doesn't toggle the
setting, it just selects the cell to the right or below.
 

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