go back to column a by clicking enter key only in a specific column

Shloime

Board Regular
Joined
Oct 25, 2023
Messages
60
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
Platform
  1. Windows
I have data to fill in let's say column A to column F, I want after i type in column f to go back to the next row in column A.
is there any way like with selection change module. if the target cell is in column F and the selection change event happened by hitting enter key then go to column a in current row
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
See if this works for you:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    If Target.Column = 6 Then Range("A" & Target.Row + 1).Select
    Application.EnableEvents = True
End Sub
 
Upvote 0
worksheet change event may be an option but I want to go back only when i click the enter key I still want to have the option to move to the right with the right arrow key etc.
 
Upvote 0
Understood. Try this in the worksheet module:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If ActiveCell.Column = 6 Then
        Application.OnKey "{ENTER}", "GoColA"
    Else
        Application.OnKey "{ENTER}"
    End If
End Sub

And put this in a standard module:
VBA Code:
Sub GoColA()
    Range("A" & ActiveCell.Row + 1).Select
End Sub
 
Upvote 0
On further testing, it looks like you need to treat the Enter & Return keys separately. Try replacing the worksheet module with the following (leave the GoColA module as it is)
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If ActiveCell.Column = 6 Then
        Application.OnKey "{ENTER}", "GoColA"
        Application.OnKey "{RETURN}", "GoColA"
    Else
        Application.OnKey "{ENTER}"
        Application.OnKey "{RETURN}"
    End If
End Sub
 
Upvote 0
On further testing, it looks like you need to treat the Enter & Return keys separately. Try replacing the worksheet module with the following (leave the GoColA module as it is)
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If ActiveCell.Column = 6 Then
        Application.OnKey "{ENTER}", "GoColA"
        Application.OnKey "{RETURN}", "GoColA"
    Else
        Application.OnKey "{ENTER}"
        Application.OnKey "{RETURN}"
    End If
End Sub
Thanks for your suggestion. this seems to work
what is the Application.OnKey "{RETURN}"?
 
Upvote 0
The return key on your keyboard acts like the enter key.
 

Attachments

  • return-key-on-keyboard-3.png
    return-key-on-keyboard-3.png
    55 KB · Views: 13
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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