Move cursor down and left, if in columns 7

Tresfjording

New Member
Joined
Dec 14, 2019
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi ...
I'm trying to move the cursor one down and one to the left if the cursor i active in column G:G

I input numbers in columns F and G.
On ENTER in column F, I want the cursor to go to the same row in column G
On ENTER in column G, I want the cursor to go one row down, and one cell to the left from active cell.

That is, if i am typing a number in F34, upon ENTER the cursor wil go to G34
And upon ENTER in G34 it will select cell F35.

I have tried to do this in VBA and here is my feeble first try:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim colname As Integer
colnmbr = 7

If Columns.Select <> Columns(colnmbr) Then

Application.MoveAfterReturnDirection = xlToRight

Else

ActiveCell.Offset(1, -1).Select
End If

End Sub

The code returns an run-time error 13
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try this:
This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  5/30/2022  8:07:29 PM  EDT

    Select Case Target.Column
        Case 6
            Target.Offset(, 1).Select
        
        Case 7
            Target.Offset(1, -1).Select
    End Select

End Sub
 
Upvote 0
Or use this they both do the same. Just another way to do it:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  5/30/2022  8:25:29 PM  EDT

    Select Case Target.Column
        Case 6
            Target(, 2).Select
        Case 7
            Target(2, -0).Select
    End Select

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,079
Messages
6,123,000
Members
449,092
Latest member
masterms

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