gheyman
Well-known Member
- Joined
- Nov 14, 2005
- Messages
- 2,341
- Office Version
- 365
- Platform
- Windows
This code works fine when my table has three fields (coulumns). But if I try to use it on a table with one column it does not. The entire table disappears.
How do I change this to work on a table that only has one field?
thanks for the help!
How do I change this to work on a table that only has one field?
Code:
Sub ClearUserList()
'Clear table - remove all rows except the first row
Application.ScreenUpdating = False
ActiveSheet.ListObjects("UserDefinedList").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("User List").ListObjects("UserDefinedList")
.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
thanks for the help!