Jen T
asked on
Excel VBA not deleting all filtered rows
hi there,
I have a little Excel VBA code that autofilters for a criteria and then deletes those that meet that criteria.
Here is the code:
This code was working fine until yesterday. For some reason, it stopped deleting all the visible rows. I'm not sure why.
I have tried replacing .Rows.Delete to .EntireRow.Delete but it doesn't work either.
I'm baffled as this was working fine (for weeks now) until yesterday. This code is applied to an automated report that is sent out daily.
Can anyone please tell me what could have gone wrong? It seems to be deleting the top half, then leaving the bottom half of the filtered rows.
Thanks in advance
I have a little Excel VBA code that autofilters for a criteria and then deletes those that meet that criteria.
Here is the code:
With rngData
.AutoFilter Field:=8, Criteria1:=Array("*Transfer"), Operator:=xlFilterValues
'Delete the visible rows while keeping the header
If .Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count > 1 Then
.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Rows.Delete
Else
End If
End With
This code was working fine until yesterday. For some reason, it stopped deleting all the visible rows. I'm not sure why.
I have tried replacing .Rows.Delete to .EntireRow.Delete but it doesn't work either.
I'm baffled as this was working fine (for weeks now) until yesterday. This code is applied to an automated report that is sent out daily.
Can anyone please tell me what could have gone wrong? It seems to be deleting the top half, then leaving the bottom half of the filtered rows.
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It was actually your suggestion to check rngData that was the issue.
The sheet it pulls in seems to have hidden rows so the last row was incorrect.
I have just added a line to unhide all rows to prevent it from happening in the future.
Again, thank you for your prompt response. You're awesome!
Jen