0

I'm trying to run a macro to change the conditional formatting in a pivot table depending on what selections the user has made. I recorded this and it seemed to work fine but now i've tried using it in anger i'm only getting the formatting applying to the top left cell that i selected (C30 in my code) whereas it should then see the next two lines of VBA where i highlight everything along to the end and bottom of the pivot data.

Could anyone help me out with where i'm going wrong?

Example below;

Sub TransactionCountFormat()

Application.ScreenUpdating = False
' TransactionCountFormat Macro
'

'
    Range("C30").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.FormatConditions.Delete
    Selection.FormatConditions.AddColorScale ColorScaleType:=3
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    Selection.FormatConditions(1).ColorScaleCriteria(1).Type = _
        xlConditionValueLowestValue
    With Selection.FormatConditions(1).ColorScaleCriteria(1).FormatColor
        .Color = 7039480
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).ColorScaleCriteria(2).Type = _
        xlConditionValuePercentile
    Selection.FormatConditions(1).ColorScaleCriteria(2).Value = 50
    With Selection.FormatConditions(1).ColorScaleCriteria(2).FormatColor
        .Color = 16776444
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).ColorScaleCriteria(3).Type = _
        xlConditionValueHighestValue
    With Selection.FormatConditions(1).ColorScaleCriteria(3).FormatColor
        .Color = 8109667
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).ScopeType = xlSelectionScope
    Application.ScreenUpdating = True
    
End Sub
braX
  • 10,905
  • 5
  • 18
  • 32
Joe
  • 1
  • You might want to read https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba – SJR Jan 11 '22 at 12:31

0 Answers0