VBA - If cell = 0, make font white?

lichldo

Board Regular
Joined
Apr 19, 2022
Messages
65
Office Version
  1. 365
Platform
  1. MacOS
Hello, I am trying to use conditional formatting but in VBA and the record macro doesn't record the code from conditional formatting

I just need any cell that = 0 to have white font

Is this possible in VBA? It needs to apply to the entire sheet

Thank you!!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi,

In your conditional formatting you can use a rule whereby if value = 0 then custom format is ;;;
 
Upvote 0
My macro recorder creates the appropriate code as expected, not sure why yours doesn't. Example (with minor tweaks):
VBA Code:
Sub Macro1()
With Sheets("Sheet1").UsedRange
    .FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=0"
    .FormatConditions(.FormatConditions.Count).SetFirstPriority
End With
With Sheets("Sheet1").UsedRange.FormatConditions(1).Font
    .ThemeColor = xlThemeColorDark1
    .TintAndShade = 0
End With
Sheets("Sheet1").UsedRange.FormatConditions(1).StopIfTrue = False
End Sub
 
Upvote 0
Solution
My macro recorder creates the appropriate code as expected, not sure why yours doesn't. Example (with minor tweaks):
VBA Code:
Sub Macro1()
With Sheets("Sheet1").UsedRange
    .FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=0"
    .FormatConditions(.FormatConditions.Count).SetFirstPriority
End With
With Sheets("Sheet1").UsedRange.FormatConditions(1).Font
    .ThemeColor = xlThemeColorDark1
    .TintAndShade = 0
End With
Sheets("Sheet1").UsedRange.FormatConditions(1).StopIfTrue = False
End Sub
the name of the sheet will not always be consistent. can it be applied to just be on the active sheet?
 
Upvote 0
Just change all references from Sheets("Sheet1") to ActiveSheet
 
Upvote 0

Forum statistics

Threads
1,216,120
Messages
6,128,948
Members
449,480
Latest member
yesitisasport

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