Excelsson
Excelsson

Reputation: 195

VBA Script to Delete Column Values based on other Column Values - Getting Type Mismatch

I have a problem with the following command, as I'm getting a

Runtime error 13 Time Mismatch

in this part:

If Cells(i, "BL").Value = "Started" Then, below the code, what can I change in order for it to run?

Pretty much want to look for the work Started in all the rows in column BL and if so, delete the information in the same row in column AH


    Dim myLastRow As Long
    Dim i As Long
    Application.ScreenUpdating = False
    'Find last row
    myLastRow = Cells(Rows.Count, "BL").End(xlUp).Row
    ' Loop through range
    For i = 2 To myLastRow
        ' If Cells(i, "BL").Value = "Started" Then Range(Cells(i, "AH")).ClearContents
        If Cells(i, "BL").Value = "Started" Then Cells(i, "AH").ClearContents
    Next i
    Application.ScreenUpdating = True


End Sub

Upvotes: 0

Views: 31

Answers (1)

Domenic
Domenic

Reputation: 8104

Does Column BL contain one or more error values? If so, you'll need to test for an error first, and then test whether the value is equal to "Start"...

For i = 2 To myLastRow
    ' If Cells(i, "BL").Value = "Started" Then Range(Cells(i, "AH")).ClearContents
    If Not IsError(Cells(i, "BL").Value) Then
        If Cells(i, "BL").Value = "Started" Then Cells(i, "AH").ClearContents
    End If
Next i

Hope this helps!

Upvotes: 1

Related Questions