Search code examples
excelvbalistobjectexcel-tables

How do I reference tables in Excel using VBA?


Is it possible in Excel VBA to reference a named table?

Hypothetically this could be...

Sheets("Sheet1").Table("A_Table").Select

I have seen some mention of tables being a list object but I'm not sure if that is the same thing.


Solution

  • Converting a range to a table as described in this answer:

    Sub CreateTable()
        ActiveSheet.ListObjects.Add(xlSrcRange, Range("$B$1:$D$16"), , xlYes).Name = _
            "Table1"
            'No go in 2003
        ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleLight2"
    End Sub