I need to search an entire Excel workbook
containing multiple sheets for
text strings that may be present in multiple columns
(say in the range column A to column J)
When a text string is found, it applies a color format to the cell.
Is this possible, or will I have to make a rule for each sheet?
An example:
- Find string "information" anywhere in my
workbook
and format cell blue
I have multiple different text strings to enter and each will have a different color format.
Is there a way to combine them all in one rule, or will this just need to have me create a new rule for each, using the same rule modified for each text string?
I'm really new at the conditional formatting in Excel, so if you could be gentle and walk me through each step that would be appreciated.
I have searched the oracle internet and found this solution. I need to test it but it may do what I need.
This requires me to build a table called ChooseColors. The first column is the search string, the second is the colors -- pick from the available range. The search area is on a second sheet -- start on this sheet.
Code:
Sub DoColors()
Dim Picker As Variant
Dim Colors As Variant
Dim Rws As Long, j As Long
Dim i As Integer
Dim Sht As String
Dim c As Range
Dim FirstAddress
Sht = ActiveSheet.Name
'load search strings and colors into arrays
Application.Goto Reference:="ChooseColors"
ReDim Picker(1 To Selection.Rows.Count)
ReDim Colors(1 To Selection.Rows.Count)
For i = 1 To Selection.Rows.Count
Picker(i) = ActiveCell.Value
Colors(i) = ActiveCell.Offset(0, 1).Interior.ColorIndex
ActiveCell.Offset(1, 0).Select
Next i
'search the test range, changing backgrounds as required
Sheets(Sht).Activate
For i = 1 To UBound(Picker)
With Cells.SpecialCells(xlCellTypeConstants, xlTextValues)
Set c = .Find(Picker(i), LookIn:=xlValues)
If Not c Is Nothing Then
FirstAddress = c.Address
Do
c.Interior.ColorIndex = Colors(i)
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> FirstAddress
End If
End With
Next i
End Sub
This code, based on the first set of code you posted, will highlight all occurrences of whatever text you type in within the workbook.
To find more than one value and format you could use the following code.
It relies on a sheet I've called
Info
which has the values to look for in the range A1:A3.The background to these values have been coloured as you want and the code just finds the matching values and copies the colour over.
You could add extra code to allow for more values, or use a dynamic named range to return your source values.
A dynamic named range would consist of a formula such as:
=Info!$A$1:INDEX(Info!$A:$A,COUNTA(Info!$A:$A))
with a given name of 'SourceValues'.Select
Define Name
on theFormula
ribbon and paste the formula into theRefers To:
box and theSourceValues
into the name.You'd then refer to the range with
Set Information = Range("SourceValues")
I'm all for a good VBA solution when it is needed... but here you are better off using Find + Replace (Ctrl + H / Cmd + H). Click the "Options" button and next to the replace you can format the text to replace it with. Select "Format" then fill then the blue color. Put "information" in both the find and replace fields and run :)