Tuesday, 6 August 2013

Coloring excel table according to highest values VBA

Coloring excel table according to highest values VBA

I have a table in excel and I want to go over each row and color the top
two highest values in each row. I'm trying to use VBA, I dont want to use
conditional formatting. this is what I wrote:
Sub top_two()
Sheets("sheet1").Select
Dim all_rows As Range
Set all_rows = Range("C6:K8")
Dim c As Range
For Each c In all_rows.Rows
For Each d In c.Cells
If d = WorksheetFunction.Large(c, 1) Or c =
WorksheetFunction.Large(c, 2) Then
d.Interior.Color = RGB(255, 0, 0)
End If
Next
Next
End sub()
the table is Range("C6:K8"), it has 3 rows now. For some reason that
doesn't work. Can someone tell me what am I doing wrong?

No comments:

Post a Comment