Forum Discussion
Adam Drummond
Mar 01, 2017Copper Contributor
How can I change the table style for all tables in a workbook simultaneously?
Hi, I have some stats software that exports tables to Excel but can only do so in one of the standard Excel table styles (e.g. Light 1, Medium 1 etc.). I have created a custom style that better f...
- Mar 02, 2017
Hi Adam
If you set a custom table style and call it MyStyle for example then use this code
Sub FormatAllTables() Dim wks As Worksheet Dim tbl As ListObject For Each wks In Worksheets For Each tbl In wks.ListObjects tbl.TableStyle = "MyStyle" Next tbl Next wks End SubCheers
Wyn Hopkins
Mar 02, 2017MVP
Hi Adam
If you set a custom table style and call it MyStyle for example then use this code
Sub FormatAllTables()
Dim wks As Worksheet
Dim tbl As ListObject
For Each wks In Worksheets
For Each tbl In wks.ListObjects
tbl.TableStyle = "MyStyle"
Next tbl
Next wks
End SubCheers
- Max_W13Jun 23, 2020Copper ContributorThanks ! That worked perfectly. I added a couple of extra lines to also change font, as that seems to not be changed with the TableStyle alone.. (??)
- JoeTorrettoJun 02, 2020Copper Contributor
Hi Wyn,
Thanks for posting this code. I'm looking to modify it slightly to only change the first table on each sheet.
Each sheet of my workbook has two tables, and I would like to change the first one on each sheet to my custom table style, while leaving the 2nd table formatted as it was previously. Do you know how I could modify this code to do that?
Thanks so much in advance for any direction you can provide.
- Wyn HopkinsJun 03, 2020MVPHi
You would most likely have to name the tables in some consistent manner e,g, myTblSales, myTblCosts so the VBA can check say the first 5 letters of the table and if its myTbl then do the change
- Adam DrummondMar 03, 2017Copper Contributor
Thanks, that's exactly what I was looking for!
- Wyn HopkinsMar 03, 2017MVPYou're welcome