Not delete row using or

  • Thread starter FIRSTROUNDKO via OfficeKB.com
  • 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
 
T

Tom Hutchins

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top