Find Cells of Certain Text Color Only within the Range Selected

norts55

Board Regular
Joined
Jul 27, 2012
Messages
191
I have a macro that someone on this forum helped me with a while back. The macro works perfectly but now I need to make a modification and the code is way above my skill level. In the current form this macro searches my entire worksheet, finds and selects all cells that are formatted with the text color RGB(1, 2, 2). I need to modify this macro so it only finds and selects cells within my current range of cells that I have selected. So, basically, I no longer want to search the entire sheet, I only want to search within my current selected range. Can someone please help with this? Thanks in advance.

Code:
Sub a_0_0_Change_Colors_to_Automatci()'
' a_0_0_Change_Colors_to_Automatci Macro
'


'
    Dim rngFound As Range
    Dim rngAll As Range
    Dim strFirst As String
    Dim lColor As Long
    
    lColor = RGB(1, 2, 2)
    
    With Application.FindFormat
        .Clear
        .Font.Color = lColor        'Search for font color
        '.Interior.Color = lColor   'Search for background color
    End With
    
    With ActiveSheet.UsedRange
        Set rngFound = .Find("", .Cells(.Cells.Count), SearchFormat:=True)
        If Not rngFound Is Nothing Then
            Set rngAll = rngFound
            strFirst = rngFound.Address
            Do
                Set rngAll = Union(rngAll, rngFound)
                Set rngFound = .Find("", rngFound, SearchFormat:=True)
            Loop While rngFound.Address <> strFirst
            
            rngAll.Select
            
            Set rngAll = Nothing
            Set rngFound = Nothing
            strFirst = vbNullString
        Else
            MsgBox "No cells found with font color " & lColor & ".", , "No Matches"
            'MsgBox "No cells found with background color " & lColor & ".", , "No Matches"
        End If
    End With
    
    Application.FindFormat.Clear
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Thank you L.Howard. That works. I can mark this as solved, but I do have another question with this macro, which maybe I should start a new thread, tell me if that is the case.

Here is the question...

If I want to find multiple colors within my selection is that possible? I need to find text color RGB(1, 2, 2), text color RGB(13, 13, 13), text color RGB(38, 38, 38), I have a few more but if I can figure out how this works I should be able to add the others.

Again, thank you L.Howard for the previous answer and thanks anyone who might have the answer to my next step.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top