I have reposted my solution, which now contains two different solutions. Here is the code for the first solution that I posted earlier. This is the code associated with the button click:
Private Sub buttonHighlight_Click()
Dim c As Range
For Each c In Me.UsedRange
If InStr(c.Formula, "-") > 0 Then
c.Interior.Color = 65535
End If
Next c
End Sub
The second solution adds a user-defined function that returns the formula in a cell. This is a more general solution that is easier for a user to manage. In this case, I added a function called CELLFORMULA that returns the formula in a cell:
Public Function CELLFORMULA(c As Range) As String
If c.Count > 1 Then
CELLFORMULA = ""
Else
CELLFORMULA = c.Formula
End If
End Function
Using this UDF, you can now construct a formula in conditional formatting to highlight the cell if it contains "-". For example, in cell B2 you would have the following rule to highlight the cell:
=NOT(ISERROR(FIND("-",CELLFORMULA(B2))))
Note: If the cell contains a "-" in any context, such as containing a negative number or a text string with a "-", this condition will be TRUE.
Bookmarks