Macro code to format a row if cell =0

lichldo

Board Regular
Joined
Apr 19, 2022
Messages
65
Office Version
  1. 365
Platform
  1. MacOS
Hello, I am trying to write a macro but I'm getting stuck as I keep getting an error.

What I want to happen is looking at my range A1:P1000, if P1 = 0, then format the whole row (A:P) with italics, strikethrough text, and grey background. And etc for P2, P3, etc would format THAT row.

This is what I have, but I think there is an error in the first few lines, I know the formatting at the bottom is correct language. Thanks for your help.


Sub ZeroFormat()
'
' ZeroFormat Macro
'

'
With Range("A1:P1000")
.FormatConditions.Add Type:=xlExpression, Formula1:="=AND(COUNTBLANK($P1)=0,$P1=0)"
.FormatConditions(.FormatConditions.Count).SetFirstPriority
Selection.Font.Italic = True
Selection.Font.Strikethrough = True
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent3
.TintAndShade = 0.799981688894314
.PatternTintAndShade = 0
End With
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
please disregard this thread I am re-posting with an update, I cannot edit
 
Upvote 0
 
Upvote 0
How about
VBA Code:
Sub ZeroFormat()
'
' ZeroFormat Macro
'

'
With Range("A1:P1000")
   .FormatConditions.Add Type:=xlExpression, Formula1:="=AND(COUNTBLANK($P1)=0,$P1=0)"
   .FormatConditions(.FormatConditions.Count).SetFirstPriority
   With .FormatConditions(1)
      .Font.Italic = True
      .Font.Strikethrough = True
      With .Interior
         .Pattern = xlSolid
         .PatternColorIndex = xlAutomatic
         .ThemeColor = xlThemeColorAccent3
         .TintAndShade = 0.799981688894314
         .PatternTintAndShade = 0
      End With
   End With
End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

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