Hello,
I have this macro that selects cells based on a font color. I need to expand this so it also only selects cells that have a value (text in the cell) and/or doesn't select empty cells (No text in the cell). The reason for this is the cells are sometimes copied around the sheet, then their contents are cleared but the formatting is still there and when this macro is ran it finds the empty cells.
I have tried this with if statements but can't seem to figure it out.
Any help would be greatly appreciated. Thanks in advance.
I have this macro that selects cells based on a font color. I need to expand this so it also only selects cells that have a value (text in the cell) and/or doesn't select empty cells (No text in the cell). The reason for this is the cells are sometimes copied around the sheet, then their contents are cleared but the formatting is still there and when this macro is ran it finds the empty cells.
I have tried this with if statements but can't seem to figure it out.
Any help would be greatly appreciated. Thanks in advance.
Code:
Sub z_Matls()
Dim rngFound As Range
Dim rngAll As Range
Dim strFirst As String
Dim lColor As Long
lColor = RGB(153, 51, 0)
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