Hi all
I have a number of tables that I want to clear as a fore runner for importing data from a number of workbooks.
The code below works but it seems inefficient and believe it could be done better using an array.
I am very confused on how Listobjects would work as part of a loop using array so hoping someone may give me a nudge in the right direction.
Regards
Mark
Sub ClrTbls()
Application.DisplayAlerts = False
'Clear Worksheet Table
With Sheet19.ListObjects("TblWrk")
If Not .DataBodyRange Is Nothing Then
.DataBodyRange.ClearContents
.DataBodyRange.Delete
End If
End With
'Clear Recoveries Table
With Sheet12.ListObjects("TblRecov")
If Not .DataBodyRange Is Nothing Then
.DataBodyRange.ClearContents
.DataBodyRange.Delete
End If
End With
'Clear Forecast Table
With Sheet13.ListObjects("TblPipe")
If Not .DataBodyRange Is Nothing Then
.DataBodyRange.ClearContents
.DataBodyRange.Delete
End If
End With
Application.DisplayAlerts = True
End Sub
I have a number of tables that I want to clear as a fore runner for importing data from a number of workbooks.
The code below works but it seems inefficient and believe it could be done better using an array.
I am very confused on how Listobjects would work as part of a loop using array so hoping someone may give me a nudge in the right direction.
Regards
Mark
Sub ClrTbls()
Application.DisplayAlerts = False
'Clear Worksheet Table
With Sheet19.ListObjects("TblWrk")
If Not .DataBodyRange Is Nothing Then
.DataBodyRange.ClearContents
.DataBodyRange.Delete
End If
End With
'Clear Recoveries Table
With Sheet12.ListObjects("TblRecov")
If Not .DataBodyRange Is Nothing Then
.DataBodyRange.ClearContents
.DataBodyRange.Delete
End If
End With
'Clear Forecast Table
With Sheet13.ListObjects("TblPipe")
If Not .DataBodyRange Is Nothing Then
.DataBodyRange.ClearContents
.DataBodyRange.Delete
End If
End With
Application.DisplayAlerts = True
End Sub