VBA code to change font color from red to black

gubertu

Board Regular
Joined
May 24, 2015
Messages
101
Hi all,

I´m looking for a code that changes in all the workbook, all the text that is in red colored (red font), into black (black font).

Would it be possible?

Thanks in advance!
 

KOKOSEK

Board Regular
Joined
Apr 8, 2019
Messages
206
Office Version
365, 2013
Platform
Windows
1 most important question: red color is hard coded or results of CF?
if hardcoded no problem: loop through all sheet, cells on each, check color and change.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
33,717
Office Version
365
Platform
Windows
Do you have any cells with a font colour other than red, or black that needs to remain as-is?
 

gubertu

Board Regular
Joined
May 24, 2015
Messages
101
Hello,

Yes, I have fonts in white, red, black and another colours.

It would be perfect to have a code that finds every text in red in the workbook and change the color into black.

Thanks!
 

Steve_

Board Regular
Joined
Apr 28, 2010
Messages
167
Hello,

Yes, I have fonts in white, red, black and another colours.

It would be perfect to have a code that finds every text in red in the workbook and change the color into black.

Thanks!

This one is going to be tricky. You are going to have to do something for me if you want this to work.

Run this code against your sheet. You will see I have Range("A1")...Please edit that to a Range that is currently the shade of red you are using.




Code:
Sub Get_Color_Code()
    Range("A1").Select
    MsgBox Selection.Font.Color
End Sub
Please post the color code. I suspect it will likely be 255.
 
Last edited:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
33,717
Office Version
365
Platform
Windows
Ok, how about
Code:
Sub gubertu()
   Dim Ws As Worksheet
   
   With Application
      .FindFormat.Clear
      .FindFormat.Font.Color = 255
      .ReplaceFormat.Clear
      .ReplaceFormat.Font.ColorIndex = xlAutomatic
   End With
   
   For Each Ws In Worksheets
      Ws.UsedRange.Replace "", "", xlPart, , , , True, True
   Next Ws
End Sub
 

gubertu

Board Regular
Joined
May 24, 2015
Messages
101
Hello, this is working almost perfect! But... what if in the same text there are part text in black font and part text in red font? In this case, it is not changed to black.

Thanks again!

Example: ASSETS in (-)
 
Last edited:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
33,717
Office Version
365
Platform
Windows
No, it won't be. The only way I know to do that would be to loop through every single used cell in each sheet, which could take a long time.

One thing, I forgot to reset the format's in the last code, it should be
Code:
Sub gubertu()
   Dim Ws As Worksheet
   
   With Application
      .FindFormat.Clear
      .FindFormat.Font.Color = 255
      .ReplaceFormat.Clear
      .ReplaceFormat.Font.ColorIndex = xlAutomatic
   End With
   
   For Each Ws In Worksheets
      Ws.UsedRange.Replace "", "", xlPart, , , , True, True
   Next Ws
   With Application
      .FindFormat.Clear
      .ReplaceFormat.Clear
   End With
End Sub
 

gubertu

Board Regular
Joined
May 24, 2015
Messages
101
Thanks for the last code.

I have an idea. What if we replace in all the workbook the text "in (-)" that is in red for the text "in (-)" in black¿?

This will solve my problem.

Thanks!
 

Forum statistics

Threads
1,085,429
Messages
5,383,620
Members
401,842
Latest member
BathAntelope

Some videos you may like

This Week's Hot Topics

Top