Re: Conditional formatting on multiple PERCENTAGE text boxes only
For anyone who wanted something similar, I FIGURED IT OUT! So happy, my first code! It is probably messy and terrible code, but it works! So this code will search the entire sheet for every text box, check to see if it has a "-" for negative percentage, and color the text red. Then it searches for > 0, basically anything else, and colors it black. This way, even though some of my text box titles have a "-" in them, they stay black. And if something was red before the data changes, this way it will change it back to black after running the code after a data change.
Now, if we want to get crazy. After this code, how would I tell it to select individual text boxes to check if they are positive and color text green? So, after this first code is done, I want it to sweep just for Text Box 172, 173, 174, 175, 176, 177, 178, 179, 180, 183, 186 and if they are > 0, then it changes just those to green.
Option Explicit
Sub conditionalFormatChange()
Dim TBox As TextBox
Dim Txt As String
For Each TBox In ActiveSheet.TextBoxes
Txt = TBox.ShapeRange.TextFrame2.TextRange.Text
With TBox.ShapeRange.TextFrame2.TextRange.Font.Fill
If InStr(Txt, "-") Then
.ForeColor.RGB = RGB(255, 0, 0)
End If
Select Case Txt
Case Is > 0
.ForeColor.RGB = RGB(0, 0, 0)
End Select
.Solid
.Transparency = 0
.Visible = msoTrue
End With
Next TBox
End Sub
Display More