Excel Cursor point move to a certain cell if condition meets

Jyotirmaya

Board Regular
Joined
Dec 2, 2015
Messages
204
Office Version
  1. 2019
Platform
  1. Windows
I am doing data entry in the excel sheet starting from column A to AB, I want a macro that if in the F column I put a text "C" then when i will press enter then the cell will move to K column then with next enter Q column then with next enter to W column in same row.

I got a piece of code

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 25 And Target.Column = 2 Then
Cells(26, 5).Select
Else
If Target.Row = 26 And Target.Column = 5 Then
Cells(50, 5).Select
Else
If Target.Row = 50 And Target.Column = 5 Then
Cells(51, 8).Select
End If
End If
End If

End Sub

With the above code when data enters in B25 then it jumps to H26 & so on....

By using the same principle is it possible to create a VBA macro to do so ??
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
See if this does what you want. If not, more details please.
To implement ..

1. Right click the sheet name tab and choose "View Code".

2. Copy and Paste the code below into the main right hand pane that opens at step 1.

3. Close the Visual Basic window & test.

4. If using Excel 2007 or later your workbook will need to be saved as a macro-enabled workbook (*.xlsm) & you will need to enable macros.

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim NextCol As Variant
  Dim tr As Long
  
  If Target.Cells.Count = 1 Then
    tr = Target.Row
    If UCase(Cells(tr, "F").Value) = "C" Then
      Select Case Target.Column
        Case 6: NextCol = "K"
        Case 11: NextCol = "Q"
        Case 17: NextCol = "W"
        Case Else: tr = ActiveCell.Row: NextCol = ActiveCell.Column
      End Select
      Cells(tr, NextCol).Select
    End If
  End If
End Sub
 
Upvote 0
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim NextCol As Variant
  Dim tr As Long
  
  If Target.Cells.Count = 1 Then
    tr = Target.Row
    If UCase(Cells(tr, "F").Value) = "C" Then
      Select Case Target.Column
        Case 6: NextCol = "K"
        Case 11: NextCol = "Q"
        Case 17: NextCol = "W"
        Case Else: tr = ActiveCell.Row: NextCol = ActiveCell.Column
      End Select
      Cells(tr, NextCol).Select
    End If
  End If
End Sub

Hi Peter thanks its working but after the W column when I press the enter again then I want to activate the next row of E column.
Another thing I want that similarly when I will have text "M" then cursor point will move to AA4 AB4 AC4 and after entering the details when I will press enter it will activate the next row of E column.
 
Upvote 0
Try

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim NextCol As Variant
  Dim tr As Long
  
  If Target.Cells.Count = 1 Then
    tr = Target.Row
    If UCase(Cells(tr, "F").Value) = "C" Then
      Select Case Target.Column
        Case 6: NextCol = "K"
        Case 11: NextCol = "Q"
        Case 17: NextCol = "W"
        Case 23: tr = tr + 1: NextCol = "F"
        Case Else: tr = ActiveCell.Row: NextCol = ActiveCell.Column
      End Select
      Cells(tr, NextCol).Select
    ElseIf UCase(Cells(tr, "F").Value) = "M" Then
      Select Case Target.Column
        Case 6: NextCol = "AA"
        Case 27: NextCol = "AB"
        Case 28: NextCol = "AC"
        Case 29: tr = tr + 1: NextCol = "F"
        Case Else: tr = ActiveCell.Row: NextCol = ActiveCell.Column
      End Select
      Cells(tr, NextCol).Select
    End If
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,586
Messages
6,125,681
Members
449,249
Latest member
ExcelMA

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