excel_2009
Active Member
- Joined
- Sep 14, 2009
- Messages
- 318
Hi excel gurus!
I was wondering if someone could help me, I've attempted to create the following vba code to apply conditional formatting to a range of cells, whenever I attempt to execute the code nothing happens, I'm sure it's a simple fix but I'm not too sure what the issue is?
Please can someone help me ?
I was wondering if someone could help me, I've attempted to create the following vba code to apply conditional formatting to a range of cells, whenever I attempt to execute the code nothing happens, I'm sure it's a simple fix but I'm not too sure what the issue is?
Code:
Sub test()
Set Rng = Range("B2:G10" & Range("B" & Rows.Count).End(xlUp).Row)
For Each c In Rng
If c.Value <> "" Then
r = c.Row
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 = 8711167
.TintAndShade = 0
End With
Selection.FormatConditions(1).ColorScaleCriteria(3).Type = _
xlConditionValueHighestValue
With Selection.FormatConditions(1).ColorScaleCriteria(3).FormatColor
.Color = 8109667
.TintAndShade = 0
End With
End If
Next
End Sub
Please can someone help me ?