Macro to go to another cell based on value of cell

t_mo31

New Member
Joined
Jan 23, 2017
Messages
9
Hi all,

I have a work project database and want to jump from one column to another if a certain value is entered. Specifically:

In column Y (from Y3 to infinity) if the cell contains the word "Red" or "Orange" then I want to jump to column DE (corresponding row).

I also want to repeat this macro for other columns, with them all jumping to DE - so do I need to write multiple macros, one for each column? The other columns are: AC, AH, AM, AS, AY, BE, BK, BQ, BW, CC, CI, CO, CU & DA

I'm very new at this so need help! Thanks

Tim
 

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.
Hi Tim. Welcome.

This code, pasted into the code window of the sheet you wish it to work on will do the trick:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim sColumn As String ' column letter


    'do nothing if rows 1 or 2 or more than 1 cell has been changed.
    If Target.Row < 3 Or Target.Cells.Count > 1 Then Exit Sub
    
    'check if cell contains red or orange
    If InStr(1, UCase(Target.Value), "RED") > 0 Or InStr(1, UCase(Target.Value), "ORANGE") > 0 Then
    
        'parse the column letter
        sColumn = Replace(Cells(1, Target.Column).Address(False, False), "1", "")
        
        'if Column is any of these, select Column DE of same row
        Select Case sColumn
            Case "Y", "AC", "AH", "AM", "AS", "AY", "BE", "BK", "BQ", "BW", "CC", "CI", "CO", "CU" & "DA"
                Range("DE" & Target.Row).Select
            
        End Select
        
    End If
End Sub
 
Last edited:
Upvote 0
Hi Tim. Welcome.

This code, pasted into the code window of the sheet you wish it to work on will do the trick:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim sColumn As String ' column letter


    'do nothing if rows 1 or 2 or more than 1 cell has been changed.
    If Target.Row < 3 Or Target.Cells.Count > 1 Then Exit Sub
    
    'check if cell contains red or orange
    If InStr(1, UCase(Target.Value), "RED") > 0 Or InStr(1, UCase(Target.Value), "ORANGE") > 0 Then
    
        'parse the column letter
        sColumn = Replace(Cells(1, Target.Column).Address(False, False), "1", "")
        
        'if Column is any of these, select Column DE of same row
        Select Case sColumn
            Case "Y", "AC", "AH", "AM", "AS", "AY", "BE", "BK", "BQ", "BW", "CC", "CI", "CO", "CU" & "DA"
                Range("DE" & Target.Row).Select
            
        End Select
        
    End If
End Sub


Thank you so much! Works great :)
 
Upvote 0

Forum statistics

Threads
1,215,470
Messages
6,124,992
Members
449,201
Latest member
Lunzwe73

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