VBA code to change font color from red to black

gubertu

Board Regular
Joined
May 24, 2015
Messages
102
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!
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

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
35,622
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
102
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
35,622
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
102
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
35,622
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
102
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,089,475
Messages
5,408,469
Members
403,208
Latest member
JFoley182

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top