Not delete row using or

  • Thread starter Thread starter FIRSTROUNDKO via OfficeKB.com
  • Start date Start date
F

FIRSTROUNDKO via OfficeKB.com

Hi,

I am stuck with the logic of the "OR" in this sub

whilst

If Cells(RowNdx, "A") <> "CAR" Then

works in the below sub

Dim LastRow As Long
Dim RowNdx As Long
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "A") <> "CAR" Then
Rows(RowNdx).Delete
End If
Next RowNdx

the replacement by

If Cells(RowNdx, "A") <> "CAR" OR Cells(RowNdx, "A") <> "BUS" Then

deletes everything

Thanks in advance
 
I suspect you need AND in your statement instead of OR. The way it is written
now, it will always return TRUE.

Assume Cells(RowNdx, "A") contains "CAR". The first test returns FALSE, so
it looks to see if Cells(RowNdx, "A") is not equal to "BUS". It does not
equal "BUS" (because it contains "CAR"), so it returns TRUE.

Hope this helps,

Hutch
 
Back
Top