I am trying to delete rows that DON'T contain certain names, the code I currently have is:
The issue is that when I run this code it gets to the end and succesfully deletes the unwanted rows but then comes up with an error :
Run-time error '1004': Delete method of Range class failed
If i choose to debug it highlights the following code:
I can't work out what the problem is, if i remove the NOT from the code and make it delete the rows i wish to keep the code works perfectly fine.
If anyone has any ideas that would be great!!
Code:
Function IsMember(v As Variant, vArray As Variant) As Boolean
Dim vLoop As Variant
For Each vLoop In vArray
If v = vLoop Then
IsMember = True
Exit Function
End If
Next vLoop
End Function
Code:
Sub Delete_Conslt()
Dim lLast As Long, i As Long
Dim vConsultants As Variant
lLast = Cells(Rows.Count, "H").End(xlUp).Row
vConsultants = Array("John Smith", "Julian Den", "Nick Richard", "Helen Walk", _
"Mark White", "Jed Walton", "Emma Sheppard", "Jill Long", "Nei Turner")
For i = lLast To 1 Step -1
If Not IsMember(Cells(i, "H"), vConsultants) Then
Cells(i, "A").EntireRow.Delete
End If
Next i
End Sub
The issue is that when I run this code it gets to the end and succesfully deletes the unwanted rows but then comes up with an error :
Run-time error '1004': Delete method of Range class failed
If i choose to debug it highlights the following code:
Code:
Cells(i, "A").EntireRow.Delete
I can't work out what the problem is, if i remove the NOT from the code and make it delete the rows i wish to keep the code works perfectly fine.
If anyone has any ideas that would be great!!