I have several textboxes on my dashboard. Each textbox is linked to a separate cell that shows a number, either negative or positive. I want the textbox number to change font color (green for positive number and red for negative number). I found the code below and it works but it only works when I run the macro with alt + F8. I want the macro to run on its own whenever the cell content changes so the textbox number font colro changes.
How can I later this code?
Sub Color_Text_InBox()
ActiveSheet.Shapes.Range(Array("TextBox 1")).Select
If Range("a1").Value < 0 Then
'<0 is better
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 176, 80)
.Transparency = 0
.Solid
End With
Selection.ShapeRange.TextFrame2.TextRange.Font.Bold = msoTrue
Else
'color the text box to show "not better"
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
.Solid
End With
Selection.ShapeRange.TextFrame2.TextRange.Font.Bold = msoTrue
End If
End Sub
How can I later this code?
Sub Color_Text_InBox()
ActiveSheet.Shapes.Range(Array("TextBox 1")).Select
If Range("a1").Value < 0 Then
'<0 is better
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 176, 80)
.Transparency = 0
.Solid
End With
Selection.ShapeRange.TextFrame2.TextRange.Font.Bold = msoTrue
Else
'color the text box to show "not better"
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
.Solid
End With
Selection.ShapeRange.TextFrame2.TextRange.Font.Bold = msoTrue
End If
End Sub