I am trying to write a macro that calls different macros and changes cell colors. So, if a cell 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 clicks on cell F25, it will take him to the macro associated with the value 1000EFG. I have already created the other macros, I just need to tie them together with this functionality. (These values are hypothetical)
The issues I am having is that no matter the values in cell D, when I click on the associated cell in the F column, it will take me to one macro and one macro only (not the correct macro associated with the value in cell D). I also am unsure of the syntax on how to change a cell color red depending on a value. I can't seem to tie these functionalities together in one macro. I will post the code I have tried below. ANY help is very much appreciated. You guys are awesome, Thanks!
Sub gotorefs()
For Each c In Worksheets("JE").Range("D7:D446")
If c.Value = "1000GP" Then
Call gotoref1
Worksheets("JE").Range("F7:F446").Select.ActiveCell.Interior.ColorIndex = 3
ElseIf c.Value = "1000MM" Then
Call gotoref2
Worksheets("JE").Range("F7:F446").Cell.Interior.ColorIndex = 3
ElseIf c.Value = "19FEST" Then
Call gotoref3
Worksheets("JE").Range("F7:F446").Cell.Interior.ColorIndex = 3
ElseIf c.Value = "20IEDU" Then
Call gotoref4
Worksheets("JE").Range("F7:F446").Cell.Interior.ColorIndex = 3
ElseIf c.Value = "20ONLC" Then
Call gotoref5
Worksheets("JE").Range("F7:F446").Cell.Interior.ColorIndex = 3
ElseIf c.Value = "20PART" Then
Call gotoref6
Worksheets("JE").Range("F7:F446").Cell.Interior.ColorIndex = 3
ElseIf c.Value = "20PRDV" Then
Call gotoref7
Worksheets("JE").Range("F7:F446").Cell.Interior.ColorIndex = 3
ElseIf c.Value = "20SPPR" Then
Call gotoref8
Worksheets("JE").Range("F7:F446").Cell.Interior.ColorIndex = 3
ElseIf c.Value = "22DANC" Then
Call gotoref9
Worksheets("JE").Range("F7:F446").Cell.Interior.ColorIndex = 3
ElseIf c.Value = "22LFLC" Then
Call gotoref10
Worksheets("JE").Range("F7:F446").Cell.Interior.ColorIndex = 3
ElseIf c.Value = "22MEDA" Then
Call gotoref11
Worksheets("JE").Range("F7:F446").Cell.Interior.ColorIndex = 3
ElseIf c.Value = "530CCH" Then
Call gotoref12
Worksheets("JE").Range("F7:F446").Cell.Interior.ColorIndex = 3
ElseIf c.Value = "60PUBL" Then
Call gotoref13
Worksheets("JE").Range("F7:F446").Cell.Interior.ColorIndex = 3
ElseIf c.Value = "74GA01" Then
Call gotoref14
Worksheets("JE").Range("F7:F446").Cell.Interior.ColorIndex = 3
ElseIf c.Value = "74GA17" Then
Call gotoref15
Worksheets("JE").Range("F7:F446").Cell.Interior.ColorIndex = 3
ElseIf c.Value = "74GA99" Then
Call gotoref16
Worksheets("JE").Range("F7:F446").Cell.Interior.ColorIndex = 3
ElseIf c.Value = "78REDV" Then
Call gotoref17
Worksheets("JE").Range("F7:F446").Cell.Interior.ColorIndex = 3
End If
Next c
End sub
Worksheets("JE").Range("F7:F446").Select.ActiveCell.Interior.ColorIndex = 3
. Apart of that, your loop tries to call all the subs in turn on the rows, while you said you want to do it only when the user clicks on theF
cell. – A.S.HWorksheet_Change
event should capture the click on cell F and call the appropriate routine. Besides, I advice you to use some naming convention for those routines, such asSub1000GP
, this will make life easier for you later. – A.S.H