I am trying to color my table rows. To do this Im using :
Range("Table2[MyColumn]")(i).EntireRow.Interior.Color = RGB(0, 154, 265)
But this does color the whole row (even outside the table). See above.
How to color the row of a table ?
CodePudding user response:
Address the list object correctly not with Range("Table2[MyColumn]")
and it will work:
ActiveSheet.ListObjects("Table2").ListRows(i).Range.Interior.Color = RGB(0,154,265)
I recommend: The VBA Guide To ListObject Excel Tables
The difference is that Range.EntireRow
will address the entire row of the sheet but ListRows
only the range of the listobject/table.
CodePudding user response:
You specifically mention to colour the entire row:
Range("Table2[MyColumn]")(i).EntireRow.Interior.Color = RGB(0,154,265)
Just drop the EntireRow
part and only that one column will be coloured:
Range("Table2[MyColumn]")(i).Interior.Color = RGB(0, 154, 265)
Edit after comment
What about intersecting? (Not tested)
R1 = Range("Table2[MyColumn]")(i).EntireRow
R2 = Range("Table2[MyColumn]")
Application.Intersect(R1, R2).Interior.Color = ...
R1 is the entire row, which even gets outside of the table.
R2 is the entire table.
The intersection is that one row, bounded by the boundaries of the table.