I want all tables on all sheets to be formatted in a certain way.

Brass Contributor

Good afternoon

I want all tables on all sheets to be formatted in a certain way.
It turns out that an error always appears on the ".AutoFilter.ShowAllData" line.
The error is as follows: "The object variable or the variable in the width block has not been defined"

Two questions:
1st I thought it was because one of the tables was empty, but they all have data. Why the error?

2nd If one of the tables is empty, is there an error? If so, how can I anticipate this problem.

Thank you for your help

------------------------------------------------- -------------------------

Sub Format_AllTables1()
          Dim T As ListObject
          Dim i As Long
          For i = 1 To Sheets.Count
                  For Each T In Sheets(i).ListObjects
                          With T
                                  .Sort.SortFields.Clear
                                  .AutoFilter.ShowAllData
                                  .TableStyle = ""
                          End With
                          With T.HeaderRowRange
                                  .Interior.Color = RGB(49, 133, 156)
                                  .Font.Size = 10
                          End With
                  Next
          Next
End Sub

1 Reply

@csoares 

Your routine worked fine for me.  I would prefer white text on the dark teal header bar and I like a bottom border on the table but such things are irrelevancies.  My table only had data on one of the rows and then only in two columns.

image.png