I have values in column D of a sheet (Sheet2) that are derived from a formula of longer values that are automatically entered in column C thru a double-click. So, the values in columnd D is a part taken from the values in column C. On a separate sheet (Sheet5), I have a list of values in the C column of that sheet. If any of the values in column D of Sheet2 equal any of the values in column C of Sheet5, I want the cell in the F column of Sheet2 to turn red. Once the F column cell in Sheet2 is red, depending on the value in column D, I want the red colored cell to become clickable which will take the user to a different sheet listing reference values associated with the value in column D. The code below does just that. **However** I would like to avoid hard coding the different values in anticipation that some of the values which require a reference code will be added or taken away from the list in column C of Sheet5.
I thought the best way to go about avoiding hard-coding was to create an array. In the first sub you'll see the commented out snip-its of code, I tried to do that but, I am unsure of how I can call the different macros since they are associated with certain values.
Thanks in advance for any help!
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range: Set c = Union(Range("D7:D446"), Range("F7:F446"))
Dim CellF As Range, CellD As Range, Cell As Range
If Not Application.Intersect(c, Range(Target.Address)) _
Is Nothing Then
Set CellF = Range("F" & Target.Row)
Set CellD = Range("D" & Target.Row)
'Dim refCodes As Variant
'refCodes = Sheet5.Range("C1:C17").Value
If CellF.Value <> "" Then
CellF.Interior.ColorIndex = 0
'If CellD.Value = refCodes.Value Then
'CellF.Interior.ColorIndex = 3
Select Case CellD.Value
Case "0GP", "0MM", "FEST", "IEDU", "ONLC", "PART", "PRDV", "SPPR", "DANC", "LFLC", "MEDA", "CCH", "POUBL", "GA01", "GA17", "GA99", "REDV"
CellF.Interior.ColorIndex = 3
Case Else
CellF.Interior.ColorIndex = 0
End Select
End If
End If
'End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set sourceRange = Nothing
If Target.Column = 6 And Target.Cells.Count = 1 And Target.Interior.ColorIndex = 3 Then
Set sourceRange = Target
Select Case Target.Offset(0, -2).Value2
Case "0GP": gotoref1
Case "0MM": gotoref2
Case "FEST": gotoref3
Case "IEDU": gotoref4
Case "ONLC": gotoref5
Case "PART": gotoref6
Case "PRDV": gotoref7
Case "SPPR": gotoref8
Case "DANC": gotoref9
Case "LFLC": gotoref10
Case "MEDA": gotoref11
Case "CCH": gotoref12
Case "PUBL": gotoref13
Case "GA01": gotoref14
Case "GA17": gotoref15
Case "GA99": gotoref16
Case "REDV": gotoref17
End Select
End If
End Sub
I thought the best way to go about avoiding hard-coding was to create an array. In the first sub you'll see the commented out snip-its of code, I tried to do that but, I am unsure of how I can call the different macros since they are associated with certain values.
Thanks in advance for any help!