Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

Excel VBA: clear tables activesheets /all sheets

Hello experts,

Following procedure allows me to clear range of tables in activesheet. I would like to have a modulated approach with InpuBox:

If you want to clear tables on activesheet please enter S. If you want to clear all tables of worksheets of activeworkbook please select enter ALL.

Sub Clear_Format_Table()

    Dim WS As Worksheet, oTbl As ListObject
    
    On Error GoTo Error_Routine
    
    Set oWS = Application.ActiveSheet
    With oWS
        'Format table
        For Each oTbl In .ListObjects
            oTbl.TableStyle = ""
        Next oTbl
        'Format range
        .Cells.ClearFormats
    End With
    
    Exit Sub
Error_Routine:
    MsgBox Err.Description, vbExclamation, "Something went wrong!"

End Sub

Open in new window


If you have questions, please contact me.
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Luis Diaz

ASKER

Tested and it works! Possible to have the same approach but instead of clearing the format of table clearing the format of sheet?

Thank you for your help?
Possible to have the same approach but instead of clearing the format of table clearing the format of sheet?

I believe that part was already handled?

With oWS
        'Format table
        For Each oTbl In .ListObjects
            oTbl.TableStyle = ""
        Next oTbl
        'Format range
        .Cells.ClearFormats
    End With
Noted. Thank you very much. I will test it and let you know.
Tested and it works! Thank you again for this useful procedure!