gheyman
Well-known Member
- Joined
- Nov 14, 2005
- Messages
- 2,338
- Office Version
- 365
- Platform
- Windows
I have code in one workbook that clears a table. It works great. performs the code in seconds. I tried to copy the code to another workbook to perform the same process but in the new workbook it takes almost 10 minutes to run. Not sure what's the difference and why it would take so long in the second workbook. (even if I put the same number of rows in both tables)
The first code is where it works in seconds
code that takes forever to run
Thanks
The first code is where it works in seconds
Code:
Sub Clear_ItemID()
'Clear table - remove all rows except the first row
Application.ScreenUpdating = False
ActiveSheet.ListObjects("ItemIDTable").HeaderRowRange.Select
'Remove the filters if one exists.
If ActiveSheet.FilterMode Then
Selection.AutoFilter
End If
'Clear all lines but the first one in the table leaving formulas for the next go round.
With Worksheets("ItemIdList").ListObjects("ItemIDTable")
.Range.AutoFilter
On Error Resume Next
.DataBodyRange.Offset(1).Resize(.DataBodyRange.Rows.Count - 1, .DataBodyRange.Columns.Count).Rows.Delete
.DataBodyRange.Rows(1).SpecialCells(xlCellTypeConstants).ClearContents
ActiveWindow.SmallScroll Down:=-10000
End With
Application.ScreenUpdating = True
Sheet1.Range("A21").Activate
End Sub
code that takes forever to run
Code:
Sub ClearTable()
'Clear table - remove all rows except the first row
Application.ScreenUpdating = False
ActiveSheet.ListObjects("TableSQDSearch").HeaderRowRange.Select
'Remove the filters if one exists.
If ActiveSheet.AutoFilterMode Or ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
'Clear all lines but the first one in the table leaving formulas for the next go round.
With Worksheets("Search").ListObjects("TableSQDSearch")
.Range.AutoFilter
On Error Resume Next
.DataBodyRange.Offset(1).Resize(.DataBodyRange.Rows.Count - 1, .DataBodyRange.Columns.Count).Rows.Delete
.DataBodyRange.Rows(1).SpecialCells(xlCellTypeConstants).ClearContents
ActiveWindow.SmallScroll Down:=-10000
End With
' Sheet2.ShowAllData
Application.ScreenUpdating = True
Range("B26").Activate
End Sub
Thanks