VBA for conditionally formatting several sheets the same

Nosamluap

New Member
Joined
May 12, 2011
Messages
25
Hi Guys,
This my first post. Your urgent help would be appreciated. I've read Mr Excels books and watched dozens of his videos and still can't grasp some of the concepts!! Anyway, I have a spreadsheet and a routine that splits it down by sales rep onto seperate sheets and that works fine. The customer has asked that I conditionally format rows based on a criteria in one column, which I also have the code for and it works fine, but only on the master sheet not those sheets the first part of the VBA creates.

I've tried using....
For Each wsNew In ActiveWorkbook.Worksheets
wsNew.Columns("A:AC").EntireColumn.AutoFit
Next

and this works fine and autofits each column, however the code I recorded for the conditional formatting won't work when using it in between the 'For each wsNew, and Next statements.

There are two conditions if that helps, and it 'appears' that the code is doing the formatting several times on the master sheet, rather than jumping to the next sheet.

Any ideas why please?
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
This is the actual VBA....

For Each wsNew In ActiveWorkbook.Worksheets
wsNew.Columns("A:AC").EntireColumn.AutoFit
Next
For Each wsNew In ActiveWorkbook.Worksheets
wsNew.Columns("Y").Hidden = True
Next
For Each wsNew In ActiveWorkbook.Worksheets
Range("A2:AC3000").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$X2>100"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = 0.599963377788629
End With
Selection.FormatConditions(1).StopIfTrue = True
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND($X2>40,$X2<99.99)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 10092543
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
Next
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,916
Members
452,949
Latest member
beartooth91

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