Link to home
Start Free TrialLog in
Avatar of Euro5
Euro5Flag for United States of America

asked on

vba error if nothing found in list

The code works well, but if there is nothing to remove, I get an error.
Emergency here...can anyone help?

Sub Remove_Intl()
Dim CalcMode As LongPtr

    With Application
        CalcMode = .Calculation
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
    End With

    With Sheets("Data")

        With Intersect(.UsedRange, .Range("AY:AY"))
            .Replace What:="International", Replacement:="#N/A", LookAt:= _
                     xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
                     ReplaceFormat:=False
            .SpecialCells(xlCellTypeConstants, 16).EntireRow.Delete
        End With

    End With

    With Application
        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
    End With

End Sub
Sub Remo

Open in new window

Avatar of Shums Faruk
Shums Faruk
Flag of India image

Try below:
Sub Remove_Intl()
Dim CalcMode As LongPtr

    With Application
        CalcMode = .Calculation
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
    End With
    
    On Error Resume Next

    With Sheets("Data")

        With Intersect(.UsedRange, .Range("AY:AY"))
            .Replace What:="International", Replacement:="#N/A", LookAt:= _
                     xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
                     ReplaceFormat:=False
            .SpecialCells(xlCellTypeConstants, 16).EntireRow.Delete
        End With

    End With
    
    On Error GoTo 0

    With Application
        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
    End With

End Sub

Open in new window

SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Euro5

ASKER

Thank you again!!
You're welcome.