ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Change enter key direction based on range (https://www.excelbanter.com/excel-programming/411112-change-enter-key-direction-based-range.html)

Mike K

Change enter key direction based on range
 
Oh Wise Ones,
I jump back in forth between several workbooks
throughout the day. Almost all of them I need the Enter key to move to the
right when pressed. I know how to manually set the direction, but for the few
ranges I need it to move down, can I have it programmatically switch
directions only in that particular range?

Many thanks,
Mike

JLGWhiz

Change enter key direction based on range
 
You might be able to adapt this into a Worksheet_Change with the Target range
being the control factor. I didn't test it.


Set MyRange = ActiveSheet.Range("C5:C25")
If Intersect(MyRange, Target) Then
Application.MoveAfterReturn = True
Application.MoveAfterReturnDirection = xlDown
Else
Application.MoveAfterReturnDirection = xlToRight
End If


"Mike K" wrote:

Oh Wise Ones,
I jump back in forth between several workbooks
throughout the day. Almost all of them I need the Enter key to move to the
right when pressed. I know how to manually set the direction, but for the few
ranges I need it to move down, can I have it programmatically switch
directions only in that particular range?

Many thanks,
Mike


Mike K

Change enter key direction based on range
 
Thanks JLG,
Didn't work when implemented as below:

Private Sub Worksheet_Change(ByVal Target As Range)
Set MyRange = ActiveSheet.Range("J3:L12")
If Intersect(MyRange, Target) Then
Application.MoveAfterReturn = True
Application.MoveAfterReturnDirection = xlDown
Else
Application.MoveAfterReturnDirection = xlToRight
End If
End Sub

Still moves to the right.

This is what I figured the code would look like, but I'm not strong enough
in vba to do it myself.

Mike

"JLGWhiz" wrote:

You might be able to adapt this into a Worksheet_Change with the Target range
being the control factor. I didn't test it.


Set MyRange = ActiveSheet.Range("C5:C25")
If Intersect(MyRange, Target) Then
Application.MoveAfterReturn = True
Application.MoveAfterReturnDirection = xlDown
Else
Application.MoveAfterReturnDirection = xlToRight
End If


"Mike K" wrote:

Oh Wise Ones,
I jump back in forth between several workbooks
throughout the day. Almost all of them I need the Enter key to move to the
right when pressed. I know how to manually set the direction, but for the few
ranges I need it to move down, can I have it programmatically switch
directions only in that particular range?

Many thanks,
Mike



All times are GMT +1. The time now is 01:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com