I'm making a tool that will cleanup excel documents so that they're in a database-friendly format (for scheduled import into a database).
As part of this tool, I want to convert all tables in the active worksheet to ranges (using VBA). The script below is almost what I want - it converts all tables to ranges for all worksheets in the workbook:
Sub ConvertTablesToRange()
Dim wks As Worksheet, objList As ListObject
For Each wks In ActiveWorkbook.Worksheets
For Each objList In wks.ListObjects
objList.Unlist
Next objList
Next wks
End Sub
Instead of doing this for all worksheets, I just want to do it for the active worksheet. How can I do this?
Convert all tables to ranges of active sheet with VBA 1. Activate the sheet you want to convert its tables, then press Alt + F11 keys to enable Microsoft Visual Basic for Applications window. 2. Click Insert > Module to create a new module script, copy and paste below code to the blank module.
Excel allows us to convert a table to a range without losing the table style. A range means a regular set of data on the worksheet. This tutorial will walk all levels of Excel users through the easy steps of converting a table to a range while keeping all table style formatting.
Select any cell in your data set. On the Home tab, in the Styles group, click Format as Table. Pick the desired table style in the gallery. In the Create Table dialog box, make sure the selected range if correct and the My table has headers box is checked, and then click OK.
This should work:
Sub ConvertTablesToRange()
Dim wks As Worksheet, objList As ListObject
Set wks = ActiveWorkbook.ActiveSheet
For Each objList In wks.ListObjects
objList.Unlist
Next objList
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With