Vishalunleashed
New Member
Dear Excel Masters,
I am intending to check if the table exists in the file while running the macro. If it exists then it should unlist or delete it and if does not then it should add it. Following is the code that I came up with. Somehow it is not completely checking the if conditions:
Sub AddDevices()
Dim tblExists As Boolean
tblExists = False
For Each o In Sheets("Input").ListObjects
If o.Name = "Scan Your Devices Here" Then tblExists = True
Next o
If (tblExists) Then
Sheets("Input").ListObjects("Scan Your Devices Here").Unlist
End If
Application.CutCopyMode = False
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$L$4"), , xlYes).Name = "Table1"
Range("Table1[[#Headers],[Column1]]").Select
ActiveCell.FormulaR1C1 = "Scan Your Devices Here"
ActiveSheet.ListObjects("Table1").Resize ActiveSheet.ListObjects("Table1").Range.Resize(Range("H1").Value)
Columns("L:M").Select
Selection.EntireColumn.Hidden = False
Range("L5").Select
End Sub
Thank you!
I am intending to check if the table exists in the file while running the macro. If it exists then it should unlist or delete it and if does not then it should add it. Following is the code that I came up with. Somehow it is not completely checking the if conditions:
Sub AddDevices()
Dim tblExists As Boolean
tblExists = False
For Each o In Sheets("Input").ListObjects
If o.Name = "Scan Your Devices Here" Then tblExists = True
Next o
If (tblExists) Then
Sheets("Input").ListObjects("Scan Your Devices Here").Unlist
End If
Application.CutCopyMode = False
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$L$4"), , xlYes).Name = "Table1"
Range("Table1[[#Headers],[Column1]]").Select
ActiveCell.FormulaR1C1 = "Scan Your Devices Here"
ActiveSheet.ListObjects("Table1").Resize ActiveSheet.ListObjects("Table1").Range.Resize(Range("H1").Value)
Columns("L:M").Select
Selection.EntireColumn.Hidden = False
Range("L5").Select
End Sub
Thank you!