mercredi 29 novembre 2017

VBA: If statement in for loop

I seem to get a mismatch error when trying to write an if statement in a for loop.

This is the piece of code where I get the error.

Dim lastRow2 As Long
    lastRow2 = Worksheets("csvFile").Cells(Rows.Count, 1).End(xlUp).Row

Dim r As Integer
    For r = 3 To lastRow2
        If Worksheets("csvFile").Cells(r, 1) = "#N/A" Then
            Rows(r).EntireRow.Delete
        End If
    Next r

So the goal is to delete the row where in the first cell "#N/A" is entered as an value.

Hope you guys can help and loads of thanks in advance.

Aucun commentaire:

Enregistrer un commentaire