Move selection right rather than down for just one cell?

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
417
Office Version
  1. 2007
Platform
  1. Windows
Is there a way to move the selection to the right (or left or up) rather than down for just one cell (I understand how to do this universally for all cells in the worksheet)?
As example, when G11 is selected and you strike Enter, the selection would go to H11 without going to G12.

The reason I don’t want G12 selected after G11 is when G12 is selected a message box appears. I don’t want to see the message after pressing Enter in G11 – only if G12 is selected by itself (not via Enter key after G11).

Thanks,
Steve
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
In the Worksheet Module:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With Application
        If Target.Address = Range("G11").Address Then
            .MoveAfterReturnDirection = xlToRight
        Else
            .MoveAfterReturnDirection = xlDown
        End If
    End With
End Sub
 
Upvote 0
In the Worksheet Module:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With Application
        If Target.Address = Range("G11").Address Then
            .MoveAfterReturnDirection = xlToRight
        Else
            .MoveAfterReturnDirection = xlDown
        End If
    End With
End Sub
Thank you very much Jaafar for your quick response. It's working perfectly.

Much appreciated,
Steve
 
Upvote 0
In the Worksheet Module:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With Application
        If Target.Address = Range("G11").Address Then
            .MoveAfterReturnDirection = xlToRight
        Else
            .MoveAfterReturnDirection = xlDown
        End If
    End With
End Sub

Hello Jaafar - I'm back,

I just noticed a slight problem with the Redirection routine. I have numerous other subroutines included in the worksheet. One of them simply copies/pastes a formula to a range. However, it bombs on the ActiveSheet.Paste line with a Run-time error ‘1004’ – Paste method of Worksheet class failed.

If I remove the Else command (.MoveAfterReturnDirection = xlDown) portion of the code (remark it out), the paste works fine. However, then the Enter button continues to move to the right.

Error.jpg

Test Sub.jpg
Here is a simplified example of where one of the other subs is failing (see attached JPG’s):
VBA Code:
Private Sub cmdTest1_Click()
     Range("P258").Select
     Selection.Copy
     Range("P33:P255").Select
     ActiveSheet.Paste
     Application.CutCopyMode = False
End Sub

Sorry,
Steve
 
Last edited:
Upvote 0
I learned a bit more. Like I said, when the
VBA Code:
   Else
      .MoveAfterReturnDirection = xlDown
is enabled I cannot run all my subroutines, particularly Copy/Paste. If I disable (remove or remark out the .MoveAfterReturnDirection = xlDown everything works fine. Here's what I noticed - when the is Else > .MoveAfterReturnDirection = xlDown is enabled if I select Copy/Paste, the Paste option is greyed out. It does not allow me to paste anything.

Hope this helps shed some light on my issue.
I wish I could have edited the previous post but it times out way too soon so I had to add this post.

Thanks,
Steve K.
 
Upvote 0
Here's a Dropbox link to a sample worksheet (TryMe1.xlsb) showing what I described above.

Again, wish I could have edited my preceding post and added this but I was too late.
 
Upvote 0
Hi EssKayKay

I haven't downloaded your sample workbook but I think the following slight amendment should prevent the error:

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With Application
        If Target.Address = Range("G11").Address Then
            .MoveAfterReturnDirection = xlToRight
        Else
            If .MoveAfterReturnDirection <> xlDown Then
                .MoveAfterReturnDirection = xlDown
            End If
        End If
    End With
End Sub
 
Upvote 0
Solution
Ahh thank you so very much Jaafar. It appears to be working as expected. I'll keep playing with this but I think this is it.

Once again - much appreciated ,
Steve
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top