2

Related to this question, I wonder if there is any way to apply conditional formatting to a table in PowerPoint, without importing an Excel-table. E.g. to change the background colour of a cell in the table depending on the value in it.

1 Answer 1

2

Yes, but only via code/macro of some sort. You'd iterate through the .Cell collection of the table, check to see that each cell has text and if so, if the value of the text converted to numeric is < 0, then set the cell's .Shape fill to whatever you like. Pass a reference to the table to this, for example:

Sub FormatTheTable(oTbl As Table)
    Dim x As Long
    Dim y As Long

    With oTbl
    For x = 1 To .Rows.Count
    For y = 1 To .Columns.Count
        If .Cell(x, y).Shape.TextFrame.HasText Then
        If CDbl(.Cell(x, y).Shape.TextFrame.TextRange.Text) < 0 Then
            .Cell(x, y).Shape.Fill.ForeColor.RGB = RGB(255, 0, 0)
        End If
        End If
    Next    ' Column
    Next    ' Row
    End With    ' otbl
End Sub
2
  • How would you catch changes in the table? Had a look at something similar-ish to what you suggest while googling, but catching the change-event of the table looks like an absolute nightmare. I could be wrong, of course.
    – eirikdaude
    Dec 18, 2015 at 16:23
  • 1
    You could be wrong. In an alternate universe, perhaps. In this one, you're absolutely correct. There's no change event for tables or any other specific shapes. About the best you can do is trap the Selection change event, and IF a shape is selected, check to see if it's a table and record that fact (in a variable or whatever, with a reference to the shape). Then on the next selection change event, see if the selection is no longer that same table, and if so, run the code above on it to do any necessary formatting changes. PowerPoint <> Excel. Dec 19, 2015 at 5:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .