Hi all,
I'm trying to handle an event with an on error line but it seems to be skipping it. I've checked my options and it's still set to only break on unhandled errors so I'm not sure what's causing it. My main aim is to filter a bunch of data and delete the visible rows, on occasion the value I'm filtering for won't exist in the data set so I want a procedure to handle this and move on to the rest of the process.
Here's my code, I've tried different options from resume next to GoTo and still no joy, the first part relating to CCN works but then breaks at the second section with a runtime 1004 error 'no cells visible'and highlights line '
I'm trying to handle an event with an on error line but it seems to be skipping it. I've checked my options and it's still set to only break on unhandled errors so I'm not sure what's causing it. My main aim is to filter a bunch of data and delete the visible rows, on occasion the value I'm filtering for won't exist in the data set so I want a procedure to handle this and move on to the rest of the process.
Here's my code, I've tried different options from resume next to GoTo and still no joy, the first part relating to CCN works but then breaks at the second section with a runtime 1004 error 'no cells visible'and highlights line '
.Range("$A$2:$AW$" & LRow).SpecialCells(xlCellTypeVisible).EntireRow.Delete' when debugging.
Any help anyone can offer would be greatly appreciated.
Code:
Sub Test()
Dim ws As Worksheet
Set ws = Sheet2
Dim LRow As Long
LRow = ws.Cells(ws.Rows.Count, "A:A").End(xlUp).Row
With ws
On Error GoTo 66
.Range("$A:$AW").AutoFilter field:=14, Criteria1:="CCN*"
.Range("$A$1:$AW$" & LRow).SpecialCells(xlCellTypeVisible).Copy Destination:=ws.Range("A1")
.Range("$A$2:$AW$" & LRow).SpecialCells(xlCellTypeVisible).EntireRow.Delete
66
.ShowAllData
End With
With ws
.Range("$A:$AW").AutoFilter field:=27, Criteria1:="*PECB*"
On Error GoTo nextline:
.Range("$A$2:$AW$" & LRow).SpecialCells(xlCellTypeVisible).EntireRow.Delete
nextline:
.ShowAllData
End With
End Sub
Last edited: