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
201
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
32,315
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
32,315
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
32,315
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,082,246
Messages
5,363,995
Members
400,772
Latest member
solbebe

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top