I'm working with a table (Excel 365) which contains 50 columns and about 7000 rows (increasing). The table is formatted as ListObject. So far so good.
Now I need to address 8 columns - not next to each other and all at once - to assign 4 different conditional formats to them. Procedure
Set condition = rng.FormatConditions.Add(xlExpression, Formula1:="=.....")
Obviousely it is not possible to create another array out of the ListObject (Message: types incompatible). At least I couldn't find a way yet. I also tried
With rng
.FormatConditions.Add
..... but VBA always asks for a "=".
Anybody any ideas? Is it possible at all? Thanks for your help!
Your task is to set
rng
to the correct Range before applying the FormatConditions. The columns of a table are accessible withListColumns
. This is a collection of all columns of a table. Therefore you can address a single column either via index or via column name (the name of a column is defined by the header cell).The range of a column can be accessed by the property
Range
. However, that includes the header row, and usually you don't want to apply the formatting to the header. Instead, you can use the propertyDataBodyRange
, this omits the header cell.To get all cells of all columns of interest, simply use the
Union
-command.So your code could look like this:
Note that once you have applied the conditional formatting to the table columns, it will "grow" when you add new rows - with other words the new rows will have the same formatting automatically.