mardi 22 décembre 2015

Go through column and replace if containing these values. If not leave as is

I want to go through column L and replace cells containing these text fields to 0. If not I want to leave as is. The code runs but stops at the first #N/A that it encounters.

Sub Drops()
    Dim i&, z&
    With Application
        .ScreenUpdating = False
        .Calculation = xlCalculationManual

        With Sheets("Input")
            i = .Cells(Rows.Count, "L").End(xlUp).Row
            For z = i To 2 Step -1
                If (.Cells(z, "L").Value2 Like "*Customer Dropoff*" _
                    Or .Cells(z, "L").Value2 Like "*RE-Ships No pick up charge*" _
                        Or .Cells(z, "L").Value2 Like "*Undeliverable Publication Mail (NO P/U CHARGE)*" _
                            Or .Cells(z, "L").Value2 Like "*RETURNS*" _
                                Or .Cells(z, "L").Value2 Like "*K2 Fed Ex*" _
                                    Or .Cells(z, "L").Value2 Like "*WorldNet Shipping*" _
                                        Or .Cells(z, "L").Value2 Like "*OSM (NO P/U COST)*" _
                                            Or .Cells(z, "L").Value2 Like "*TEST PICK UP*") Then

                    .Cells(z, "L").Value2 = 0
                End If
            Next z
            z = .Cells(Rows.Count, "L").End(xlUp).Row
        End With

        .ScreenUpdating = True
        .Calculation = xlCalculationAutomatic
    End With
    MsgBox i - z & " Rows has been changed!"
End Sub

Aucun commentaire:

Enregistrer un commentaire