GOTO a specific cell, based on another cell's data

%3CLINGO-SUB%20id%3D%22lingo-sub-2168991%22%20slang%3D%22en-US%22%3EGOTO%20a%20specific%20cell%2C%20based%20on%20another%20cell's%20data%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2168991%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20spreadsheet%20where%20I%20would%20like%20to%20move%20to%20a%20specific%20column%2C%20based%20on%20the%20data%20entered.%26nbsp%3B%20For%20example%3A%3C%2FP%3E%3CP%3EIn%20A1%2C%20I%20enter%20a%20name%3A%26nbsp%3B%20Joe%3C%2FP%3E%3CP%3EIf%20Joe%20is%20entered%2C%20I%20want%20to%20go%20directly%20to%20column%20J%20in%20the%20same%20row%2C%20(without%20having%20to%20either%20tab%20through%20the%20columns%2C%20or%20use%20my%20mouse%20to%20get%20me%20to%20column%20J).%20and%20enter%20more%20data.%3C%2FP%3E%3CP%3EIf%20I%20enter%20a%20different%20name%20in%20A1%3A%26nbsp%3B%20Mary%3C%2FP%3E%3CP%3EIf%20Mary%20is%20entered%2C%20I%20want%20to%20go%20directly%20to%20column%20H%20in%20the%20same%20row%20and%20enter%20more%20data.%3C%2FP%3E%3CP%3EI%20want%20to%20be%20able%20to%20do%20this%20in%20every%20row%2C%20e.g.%2C%20I%20enter%20Joe%20in%20A2%2C%20then%20go%20directly%20to%20column%20J2%2C%20etc.%3C%2FP%3E%3CP%3EThe%20data%20entered%20in%20column%20A%20is%20a%20specific%20list%20of%20names.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2168991%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2169423%22%20slang%3D%22en-US%22%3ERe%3A%20GOTO%20a%20specific%20cell%2C%20based%20on%20another%20cell's%20data%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2169423%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F354533%22%20target%3D%22_blank%22%3E%40Sue_G%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20will%20need%20a%20macro%20for%20that.%20If%20you%20right%20click%20on%20your%20worksheet%20and%20copy%2Fpaste%20this%20code%20into%20the%20code%20window%20that%20appears%2C%20then%20I%20believe%20it%20should%20work.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20will%20need%20to%20add%20the%20additional%20names%20to%20the%20code%20(the%20%22case%22%20statement).%20But%2C%20you%20should%20be%20able%20to%20just%20copy%2Fpaste%20one%20of%20the%20other%20entries%2C%20then%20change%20the%20name%20and%20the%20destination%20column.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%0A%20%20%20%20%20Dim%20destCol%20As%20Range%0A%20%20%20%20%20%0A%20%20%20%20%20On%20Error%20GoTo%20ErrHandler%0A%20%20%20%20%20%0A%20%20%20%20%20If%20Intersect(Target.Cells(1)%2C%20Me.Range(%22A%3AA%22))%20Is%20Nothing%20Then%0A%20%20%20%20%20%20%20%20%20%20Exit%20Sub%0A%20%20%20%20%20End%20If%0A%20%20%20%20%20%0A%20%20%20%20%20Select%20Case%20LCase(Target.Cells(1).Value)%0A%20%20%20%20%20%20%20%20%20%20Case%20vbNullString%3A%20Exit%20Sub%0A%20%20%20%20%20%20%20%20%20%20Case%20%22joe%22%3A%20Set%20destCol%20%3D%20Me.Range(%22J%3AJ%22)%0A%20%20%20%20%20%20%20%20%20%20Case%20%22mary%22%3A%20Set%20destCol%20%3D%20Me.Range(%22H%3AH%22)%0A%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20'%2F%2F%20%20Add%20additional%20names%20here.%20Here%2C%20the%20names%20should%0A%20%20%20%20%20%20%20%20%20%20'%2F%2F%20%20be%20in%20lowercase%2C%20but%20the%20user%20can%20key%20them%20in%20any%20case.%0A%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20Case%20Else%3A%20Err.Raise%20Number%3A%3DvbObjectError%20%2B%20520%2C%20Description%3A%3D%22Name%20not%20recognized.%22%0A%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20End%20Select%0A%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20If%20Not%20destCol%20Is%20Nothing%20Then%0A%20%20%20%20%20%20%20%20%20%20Intersect(Target.Cells(1).EntireRow%2C%20destCol).Select%0A%20%20%20%20%20End%20If%0A%20%20%20%20%20%0AExitProc%3A%0A%20%20%20%20%20Exit%20Sub%0A%20%20%20%20%20%0AErrHandler%3A%0A%20%20%20%20%20MsgBox%20%22Error%20%22%20%26amp%3B%20Err.Number%20%26amp%3B%20%22%3A%20%22%20%26amp%3B%20Err.Description%0A%20%20%20%20%20Resume%20ExitProc%0A%20%20%20%20%20%20%20%20%20%20%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2169471%22%20slang%3D%22en-US%22%3ERe%3A%20GOTO%20a%20specific%20cell%2C%20based%20on%20another%20cell's%20data%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2169471%22%20slang%3D%22en-US%22%3EThis%20works%20great!%20Thank%20you%20so%20very%20much!!!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2169479%22%20slang%3D%22en-US%22%3ERe%3A%20GOTO%20a%20specific%20cell%2C%20based%20on%20another%20cell's%20data%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2169479%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F354533%22%20target%3D%22_blank%22%3E%40Sue_G%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%2C%20by%20chance%2C%20you%20want%20it%20to%20return%20to%20column%20A%20after%20keying%20the%20data%20in%20another%20column%2C%20then%20you%20could%20change%20this%20part%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EIf%20Intersect(Target.Cells(1)%2C%20Me.Range(%22A%3AA%22))%20Is%20Nothing%20Then%0A%20%20%20%20%20Exit%20Sub%0AEnd%20If%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eto%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%20%20%20%20%20With%20Target%0A%20%20%20%20%20%20%20%20%20%20If%20Intersect(.Cells(1)%2C%20Me.Range(%22A%3AA%22))%20Is%20Nothing%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20With%20.Cells(.Cells.Count)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20If%20.Row%20%26lt%3B%20Me.Rows.Count%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Intersect(.Offset(1%2C%200).EntireRow%2C%20Me.Range(%22A%3AA%22)).Select%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20End%20With%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Exit%20Sub%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20%20End%20With%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Contributor

I have a spreadsheet where I would like to move to a specific column, based on the data entered.  For example:

In A1, I enter a name:  Joe

If Joe is entered, I want to go directly to column J in the same row, (without having to either tab through the columns, or use my mouse to get me to column J). and enter more data.

If I enter a different name in A1:  Mary

If Mary is entered, I want to go directly to column H in the same row and enter more data.

I want to be able to do this in every row, e.g., I enter Joe in A2, then go directly to column J2, etc.

The data entered in column A is a specific list of names.

8 Replies

@Sue_G 

 

You will need a macro for that. If you right click on your worksheet and copy/paste this code into the code window that appears, then I believe it should work.

 

You will need to add the additional names to the code (the "case" statement). But, you should be able to just copy/paste one of the other entries, then change the name and the destination column.

Private Sub Worksheet_Change(ByVal Target As Range)
     Dim destCol As Range
     
     On Error GoTo ErrHandler
     
     If Intersect(Target.Cells(1), Me.Range("A:A")) Is Nothing Then
          Exit Sub
     End If
     
     Select Case LCase(Target.Cells(1).Value)
          Case vbNullString: Exit Sub
          Case "joe": Set destCol = Me.Range("J:J")
          Case "mary": Set destCol = Me.Range("H:H")
          
          '//  Add additional names here. Here, the names should
          '//  be in lowercase, but the user can key them in any case.
          
          Case Else: Err.Raise Number:=vbObjectError + 520, Description:="Name not recognized."
          
     End Select
          
     If Not destCol Is Nothing Then
          Intersect(Target.Cells(1).EntireRow, destCol).Select
     End If
     
ExitProc:
     Exit Sub
     
ErrHandler:
     MsgBox "Error " & Err.Number & ": " & Err.Description
     Resume ExitProc
          
End Sub

 

This works great! Thank you so very much!!!

@Sue_G 

 

If, by chance, you want it to return to column A after keying the data in another column, then you could change this part:

 

If Intersect(Target.Cells(1), Me.Range("A:A")) Is Nothing Then
     Exit Sub
End If

 

to:

     With Target
          If Intersect(.Cells(1), Me.Range("A:A")) Is Nothing Then
               With .Cells(.Cells.Count)
                    If .Row < Me.Rows.Count Then
                         Intersect(.Offset(1, 0).EntireRow, Me.Range("A:A")).Select
                    End If
               End With
               
               Exit Sub
               
          End If
     End With
Thank you! I'll make a note of this as I'm not sure this is what I want for this spreadsheet. I wanted the cursor to move to a specific column to enter data, but I have more data to enter in other columns. I just wanted the cursor to go to the first column for that particular name.

@Sue_G 

 

Als Makro kann ich Ihnen das anbieten:

sub jump()
if Range ("A1"). value <> "Joe" then Range ("J1"). select
end sub 

 

 

I would be happy to know if I could help.

 

Nikolino

I know I don't know anything (Socrates)

 

* Kindly Mark and Vote this reply if it helps please, as it will be beneficial to more Community members reading here.

@JMB17 

After testing the spreadsheet, I decided I would like to have the cursor return to column A as you suggested. The code you provided does that, however, is it possible to have the cursor move to the target column only on the tab key, and back to column A only when I use the enter key. The way it works now, is after I enter data in my target column, whether I tab or enter, the cursor returns to column A. In some cases, I need to enter data in not only my target column, but a few following columns in that same row.  I've attached a copy of the spreadsheet so you can see what I'm working with.

 

@Sue_G 

 

Thanks for uploading the workbook, that helps quite a bit.

 

I added some additional procedures that will reassign the Enter key behavior (both the standard enter key and the numeric keypad enter key) to run a procedure when they are pressed that will go to Column A (next row down).

 

The enter keys will be reassigned when

1) the workbook is opened and Sheet1 is the active sheet.

2) Sheet1 is activated (switching between worksheets).

3) the workbook is activated and Sheet1 is the active sheet (switching between workbooks).

 

The enter keys normal function should be restored when

1) the workbook is closed.

2) the worksheet is deactivated (switching to another worksheet).

3) the workbook is deactivated (switching to another workbook).

 

So, when Column D changes, it should go to the specified column and you should be able to continue to tab/arrow across the worksheet or select with the mouse. Then, hit enter and return to column A. This behavior should only apply to Sheet1 and shouldn't affect other worksheets/workbooks.

 

You are the best! Thank you so very much...it works like a charm!!!