Find text in a cell that is a different font color

jscranton

Well-known Member
Joined
May 30, 2011
Messages
707
Someone went through a workbook and changed the font within cells (NOT the whole cell) to a different color. I need to capture all the text with a different font color (yellow). I can use this if i step through every character in every cell:

If cel.Characters(y, 1).Font.ColorIndex = 6 then

is there a way to tell if a cell contains a certain font color when it might contain more than one color (without looping through the entire text string)?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Short answer is no.

VBA will have to search each cell by character to check for color changes !
 
Upvote 0
Short answer is no.

VBA will have to search each cell by character to check for color changes !
No, that is not correct... there is a way to test the entire cell.

Code:
If Range("A1").Font.Color = Null Then
  MsgBox "The cell has two or more characters with different font colors"
End If

The OP will need to examine each cell in a loop and if the above test for that cell is Null, then fix the color (I guess). I think the OP will also have to test to see if the font color is not black as well (just in case all of the text were made a different color.
 
Upvote 0
Thanks Rick, but does this assume the default color constant is Black ??

Code:
Range("A1").Font.Color = Null
 
Upvote 0
On testing that code didn't return the message regardless of font color OR times it appears !

Code:
Range("A1").Font.Color = Null
 
Upvote 0
Thanks Rick, but does this assume the default color constant is Black ??

Code:
Range("A1").Font.Color = Null
I'm sorry, I was distracted before I had to do a chore for my wife. I should have remembered that you cannot test for Null with the equal operator:oops:... VB has a function (IsNull) that should be used. Try this code instead of what I posted earlier...
Code:
If IsNull(Range("A1").Font.Color) Then
  MsgBox "The cell has two or more characters with different font colors"
End If
 
Upvote 0
Yep, that works...thank you for the updated infor.....that should make to OP's task a little quicker as well..(y)
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,183
Members
449,071
Latest member
cdnMech

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