Forum Discussion
Sue_G
Feb 26, 2021Brass Contributor
GOTO a specific cell, based on another cell's data
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 th...
JMB17
Feb 26, 2021Bronze Contributor
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
Sue_G
Feb 26, 2021Brass Contributor
This works great! Thank you so very much!!!