Forum Discussion

Sameer_Kuppanath_Sultan's avatar
Sameer_Kuppanath_Sultan
Brass Contributor
Dec 28, 2020
Solved

VBA to move to a specific cells after Pressing "Enter"

Hi All

Happy Chrismas and New Year

 

Please, I have code below. It helps me to move to right cell after entering data either in "C" or "D".

 

But I need to modify this code that- to move the selection to "C" in a next row after entering the data in "E"- Can any one help on this??

 

 

 

Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range
Dim B As Range

Set A = Range("c:d")

If Intersect(Target, A) Is Nothing Then Exit Sub
Target.Offset(0, 1).Activate

Application.EnableEvents = True
End Sub

  • Sameer_Kuppanath_Sultan 

     

    Private Sub Worksheet_Change(ByVal Target As Range)
    
         If Not Intersect(Target, Me.Range("c:d")) Is Nothing Then
              Target.Offset(0, 1).Activate
         ElseIf Not Intersect(Target, Me.Range("e:e")) Is Nothing Then
              Target.Offset(1, -2).Activate
         End If
    
    End Sub

     

    As a side note, if you hit the tab key after inputting into Columns C and D and then hit the enter key after inputting into Column E, that would also give you the desired effect. 

     

2 Replies

  • JMB17's avatar
    JMB17
    Bronze Contributor

    Sameer_Kuppanath_Sultan 

     

    Private Sub Worksheet_Change(ByVal Target As Range)
    
         If Not Intersect(Target, Me.Range("c:d")) Is Nothing Then
              Target.Offset(0, 1).Activate
         ElseIf Not Intersect(Target, Me.Range("e:e")) Is Nothing Then
              Target.Offset(1, -2).Activate
         End If
    
    End Sub

     

    As a side note, if you hit the tab key after inputting into Columns C and D and then hit the enter key after inputting into Column E, that would also give you the desired effect. 

     

Resources