I have written the vba code below to filter a table field (account) for the value 2010 and then delete all visible data rows. I receive a run-time error 1004 on the following line:
However, if change that line to this:
Excel will ask me if I want to delete the entire row. Upon saying yes the code finishes executing perfectly. Is anyone able to tell me what is wrong with my code or why it won't execute when ".EntireRow.Delete" is used? Your help would be greatly appreciated! Here is the code as it stands right now:
VBA Code:
VisibleRows.EntireRow.Delete
However, if change that line to this:
VBA Code:
VisibleRows.Delete
Excel will ask me if I want to delete the entire row. Upon saying yes the code finishes executing perfectly. Is anyone able to tell me what is wrong with my code or why it won't execute when ".EntireRow.Delete" is used? Your help would be greatly appreciated! Here is the code as it stands right now:
VBA Code:
Sub DeleteRows2010()
Dim tbl As ListObject
Dim AccountColumn As Range
Dim FilterRange As Range
Dim VisibleRows As Range
Application.ScreenUpdating = False
Set tbl = Worksheets("GL Balance").ListObjects("tbl_GLBalance")
Set AccountColumn = tbl.ListColumns("Account").Range
Set FilterRange = tbl.Range
tbl.Range.AutoFilter Field:=tbl.ListColumns("Account").Index, Criteria1:="2010"
Set VisibleRows = tbl.DataBodyRange.Offset(1).Resize(tbl.DataBodyRange.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
If Not VisibleRows Is Nothing Then
VisibleRows.Delete
End If
tbl.AutoFilter.ShowAllData
Application.ScreenUpdating = True
End Sub