R
RonS
I've been able to created the following VB code, but it takes almost 30 seconds or more to run when the worksheet is activated. I need to know if there is a better way or place to run the code? It would be great if I could get it to run whenever a cell value is changed to Red, Blue, Green, or Amber. I want to use this in a spreadsheet for project milestones ranked as RAG or Blue that are imported from a MS Project Plan file. I've tried to use the same code with another module, Private Sub Worksheet_Calculate(), but it still takes to long to run. What is the fastest way that I can make this code run?
Private Sub Worksheet_Activate()
Dim oCell As Range
For Each oCell In Range("N17:N151")
Select Case oCell.Value
Case "Red"
oCell.Interior.ColorIndex = 3
oCell.Font.ColorIndex = 1
oCell.Font.Bold = True
Case "Blue"
oCell.Interior.ColorIndex = 5
oCell.Font.ColorIndex = 2
oCell.Font.Bold = True
Case "Green"
oCell.Interior.ColorIndex = 4
oCell.Font.ColorIndex = 1
oCell.Font.Bold = True
Case "Amber"
oCell.Interior.ColorIndex = 6
oCell.Font.ColorIndex = 1
oCell.Font.Bold = True
Case "Complete"
oCell.Interior.ColorIndex = 1
oCell.Font.ColorIndex = 2
oCell.Font.Bold = True
End Select
Next oCell
For Each oCell In Range("BF261:BF276")
Select Case oCell.Value
Case "Red"
oCell.Interior.ColorIndex = 3
oCell.Font.ColorIndex = 1
oCell.Font.Bold = True
Case "Blue"
oCell.Interior.ColorIndex = 5
oCell.Font.ColorIndex = 2
oCell.Font.Bold = True
Case "Green"
oCell.Interior.ColorIndex = 4
oCell.Font.ColorIndex = 1
oCell.Font.Bold = True
Case "Amber"
oCell.Interior.ColorIndex = 6
oCell.Font.ColorIndex = 1
oCell.Font.Bold = True
Case "Complete"
oCell.Interior.ColorIndex = 1
oCell.Font.ColorIndex = 2
oCell.Font.Bold = True
End Select
Next oCell
End Sub
Private Sub Worksheet_Activate()
Dim oCell As Range
For Each oCell In Range("N17:N151")
Select Case oCell.Value
Case "Red"
oCell.Interior.ColorIndex = 3
oCell.Font.ColorIndex = 1
oCell.Font.Bold = True
Case "Blue"
oCell.Interior.ColorIndex = 5
oCell.Font.ColorIndex = 2
oCell.Font.Bold = True
Case "Green"
oCell.Interior.ColorIndex = 4
oCell.Font.ColorIndex = 1
oCell.Font.Bold = True
Case "Amber"
oCell.Interior.ColorIndex = 6
oCell.Font.ColorIndex = 1
oCell.Font.Bold = True
Case "Complete"
oCell.Interior.ColorIndex = 1
oCell.Font.ColorIndex = 2
oCell.Font.Bold = True
End Select
Next oCell
For Each oCell In Range("BF261:BF276")
Select Case oCell.Value
Case "Red"
oCell.Interior.ColorIndex = 3
oCell.Font.ColorIndex = 1
oCell.Font.Bold = True
Case "Blue"
oCell.Interior.ColorIndex = 5
oCell.Font.ColorIndex = 2
oCell.Font.Bold = True
Case "Green"
oCell.Interior.ColorIndex = 4
oCell.Font.ColorIndex = 1
oCell.Font.Bold = True
Case "Amber"
oCell.Interior.ColorIndex = 6
oCell.Font.ColorIndex = 1
oCell.Font.Bold = True
Case "Complete"
oCell.Interior.ColorIndex = 1
oCell.Font.ColorIndex = 2
oCell.Font.Bold = True
End Select
Next oCell
End Sub