Apply Conditional Formatting to all Worksheets

BlueDevil911

New Member
Joined
Jun 1, 2018
Messages
3
I have a workbook that I generate each day from my company. I need to highlight any cells less than 0 in Red. I recorded the macro to do this on one page but when I added in the loop it only works for the sheet I am on and will not go to the next. The data on each sheet changes so I cant select the same range on each sheet. In addition, I would like to turn off show zeros for the workbook in the same macro. I cant just format the 0 to white as some rows are shaded. Thanks!

Code:
Sub CFLessthan0RedALLWS()
    Dim ws As Worksheet
    
    For Each ws In ActiveWorkbook.Worksheets
      
        Cells.Select
        Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
        Formula1:="=0"
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        
        With Selection.FormatConditions(1).Font
            .Color = -16383844
            .TintAndShade = 0
        End With
        
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 13551615
            .TintAndShade = 0
        End With
        
        Selection.FormatConditions(1).StopIfTrue = False
        Range("A1").Select
        
    Next ws

End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Sorry, forgot to mention that I am storing the Macro in my Personal Workbook and adding the shortcut to the ribbon.
 
Upvote 0
Hi & welcome to the board.
How about
Code:
Sub CFLessthan0RedALLWS()
   Dim ws As Worksheet
   
   For Each ws In ActiveWorkbook.Worksheets
      
      With ws.UsedRange
         .FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
            Formula1:="=0"
         .FormatConditions(.FormatConditions.Count).SetFirstPriority
      
         With .FormatConditions(1).Font
            .Color = -16383844
            .TintAndShade = 0
         End With
         
         With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 13551615
            .TintAndShade = 0
         End With
      
        .FormatConditions(1).StopIfTrue = False
      End With
      
   Next ws

End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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