Conditional Formatting Macro - grey out blank cells

mjd

Board Regular
Joined
Feb 23, 2010
Messages
73
Hi,

I'm working on a project (in excel 2010) that reviews financial data for hundreds of accounts on a daily, weekly, monthly, quarterly and yearly basis. I've got the analytics all squared away, but the sheet is massive and is printed so that the board can review things. some accounts have not been open long enough to have monthly/yearly data, and I'd like to grey out those cells. The conditional formatting I've tried to incorporate into my macro is as follows:

Code:
    Range("H10:AD150").Select
    Range("AD10").Activate
    Application.CutCopyMode = False
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=LEN(TRIM(AD10))=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = -0.349986266670736
    End With
    Selection.FormatConditions(1).StopIfTrue = False

Now, this fails in many ways. Greys out non-blank cells, leaves some blank cells without a background.

here is the full code:
Code:
Sub format()
    'ChDir "C:\"
    'ActiveWorkbook.SaveAs Filename:= _
        "C:\temp.xlsm", FileFormat:= _
        xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
 
    Columns("B:AE").Select
    Selection.Copy
    ActiveWindow.ScrollColumn = 1
    Range("B1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
    Cells.FormatConditions.Delete
    Rows("9:59").Select
    ActiveWorkbook.Worksheets("Muni").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Muni").Sort.SortFields.Add Key:=Range("M10:M59"), _
        SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Muni").Sort
        .SetRange Range("A9:AH59")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
 
    Rows("9:9").Select
    Selection.EntireRow.Hidden = True
 
    Rows("10:59").Select
    Selection.FormatConditions.Delete
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=MOD(ROW()-9,1*2)+1<=1"
    Selection.FormatConditions(1).Interior.ColorIndex = 45
 
    Range("AG10").Select
    ActiveCell.Formula = "=M10&"" bps"""
    Range("AG10").Select
    Selection.AutoFill Destination:=Range("AG10:AG59"), Type:=xlFillDefault
    Range("AG10:AG59").Select
    Selection.Copy
    Range("M10").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
    Range("H10:AD59").Select
    Range("AD10").Activate
    Application.CutCopyMode = False
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=LEN(TRIM(AD10))=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = -0.349986266670736
    End With
    Selection.FormatConditions(1).StopIfTrue = False
 
End Sub

Any ideas? The data changes often and the sort in the macro makes greying things out manually a foolish use of time.

Thanks,
Mike
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Maybe this

Code:
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=LEN(TRIM([B][COLOR=blue]$[/COLOR][/B]AD10))=0"

M.
 
Upvote 0
Hey,

Marcelo, I took your idea and ran with it. This variation of the code worked perfectly:

Code:
    Range("h10").Activate
    Application.CutCopyMode = False
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=LEN(TRIM(h10))=0"

Thanks for your input!
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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