I am trying to write a macro that calls different macros and changes cell colors. So, if a cell(s) in the entire column D (D4:D446) equals a certain value, THIS macro will call a separate macro associated with that value.
In other words, What I want is, for example, if any or multiple cells in range (D7:D446) = "1000ABC", "1000EFG", or "1000HIJ" any/all cells in column F7:F446 will turn red to indicate to the user that they need to click on that cell in F7:F446 and when the user clicks on that cell in column F, it will call the correct macro I already created.
Example: if cell D25="1000EFG" cell F25 will turn red and when the user bring their cursor over cell F25 and clicks on cell F25, it will take them to the macro associated with the value 1000EFG. I have already created the other macros associated with those particular values, I just need the cells in the F column to change color and become clickable to the user and when clicked, call a certain macro. I will post the code I have tried below. ANY help is very much appreciated. You guys are awesome, Thanks!
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
c = Range("D7:D446")
For Each c In Intersect(ActiveCell, Range("D7:D446")) 'this is where the error is occuring
Select Case c.Value
Case "1000GP", "1000MM", "19FEST", "20IEDU", "20PART", "20PRDV", "20SPPR", "22DANC", "22LFLC", "22MEDA", "530CCH", "60POUBL", "74GA01", "74GA17", "74GA99", "78REDV"
Cells(c.Row, "F").Interior.ColorIndex = 3
Case Else
Cells(c.Row, "F").Interior.ColorIndex = 0
End Select
Next c
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 6 And Target.Cells.Count = 1 And Target.Interior.ColorIndex = 3 Then
Cancel = True
' Now call the appropriate routine according to column C
Select Case Target.Offset(0, -3).Value2
Case "1000GP": gotoref1
Case "1000MM": gotoref2
Case "19FEST": gotoref3
Case "20IEDU": gotoref4
Case "20ONLC": gotoref5
Case "20PART": gotoref6
Case "20PRDV": gotoref7
Case "20SPPR": gotoref8
Case "22DANC": gotoref9
Case "22LFLC": gotoref10
Case "22MEDA": gotoref11
Case "530CCH": gotoref12
Case "60PUBL": gotoref13
Case "74GA01": gotoref14
Case "74GA17": gotoref15
Case "74GA99": gotoref16
Case "78REDV": gotoref17
End Select
End If
End Sub
c = Range("D7:D446"), as it will just generate an error, and you are resetting the value ofcon the very next line anyway.Range("D7:D466"). If something outside that range changes your code will bomb withobject required error. You can test this withIf Not Intersect(Target,Range("D7:D466")) is Nothing Then ... your code ... End If