An error appears when formatting all tables on all sheets.

Occasional Contributor

When running this code, the error appears "the variable of the object or the variable of the block with has not been defined.".
The code was running fine and suddenly this error starts to appear.
What could be wrong? Thank you for your help.

2 Replies
best response confirmed by csoares (Occasional Contributor)


The most probable explanation that you have a table (ListObject) that consists only of the header row - no data rows have been added yet. In that situation, its DataBodyRange will be Nothing, causing the error you see. You can prevent this by adding a check:


            If Not T.DataBodyRange Is Nothing Then
                With T.DataBodyRange
                End With
            End If


Thank you very much for your help, solved my problem