Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA Excel check if a particular table exist using table name

I have several tables in an excel sheet. Each having unique table Name. I want to know if a table which has a name "Table123" exist or not in the current sheet.

Could some one help me on this?

Thanks Jeevan

like image 496
Jeevan Avatar asked Dec 02 '22 14:12

Jeevan


2 Answers

TableExists = False
On Error GoTo Skip
If ActiveSheet.ListObjects("Table123").Name = "Table123" Then TableExists = True
Skip:
    On Error GoTo 0

This code will work and avoid loops and errors

like image 163
RGA Avatar answered Dec 22 '22 00:12

RGA


Here is an alternative function:

Function TableExistsOnSheet(ws As Worksheet, sTableName As String) As Boolean
    TableExistsOnSheet = ws.Evaluate("ISREF(" & sTableName & ")")
End Function
like image 35
Rory Avatar answered Dec 21 '22 23:12

Rory