Delete all rows that do not have the value: Criteria 1 or Criteria 2 or Criteria 3 in Column D --> Using VBA Macro for excel

Posted by JDS on Stack Overflow See other posts from Stack Overflow or by JDS
Published on 2013-10-30T21:40:47Z Indexed on 2013/10/30 21:54 UTC
Read the original article Hit count: 415

Filed under:
|
|

I am new to Macro's/VBA and cannot seem to figure out how to do this action for multiple criteria. I am trying to Delete all rows that do not have the value: Identify Fail or Identify Success in Column D. I write the following code and it works for one criteria "Identify Fail":

'***********************************************'

Sub DeleteRows()
'Action 1 --> Delete all Rows without Identify Fail in column D'
Application.ScreenUpdating = False

For i = Range("D" & Rows.Count).End(xlUp).Row To 1 Step -1
    If Range("D" & i).Value <> "Identify Fail" Then Rows(i).Delete shift:=xlUp
Next i

Application.ScreenUpdating = True
End Sub

'***********************************************'

Once I try to add 'OR' with another criteria it does not work:

'***********************************************'

Sub DeleteRows()
'Action 1 --> Delete all Rows without Identify Fail in column D'
Application.ScreenUpdating = False

For i = Range("D" & Rows.Count).End(xlUp).Row To 1 Step -1
    If Range("D" & i).Value <> "Identify Fail" Or "Identify Success" Then   
Rows(i).Deleteshift:=xlUp
Next i

Application.ScreenUpdating = True
End Sub

'***********************************************'

Any suggestions would be appreciated as I have been scouring this website and have not found an efficient code that will do the trick.

© Stack Overflow or respective owner

Related posts about excel

Related posts about vba