PDA

View Full Version : Solved: Mulitple If function?



alivenwell
12-10-2007, 07:46 AM
Hi all, I am trying to do a loop which deletes a row of data containing mulitple strings

For U = 2 To outRow
If Cells(U, 5).Value = "Blue" Or Cells(U, 5).Value = "Purple" Or Cells(U, 5).Value = "Pink" Then
Rows(U).Delete
End If
Next

But it doesn't seem to work. Does anyone know what is happening?

xld
12-10-2007, 07:56 AM
For U = outRow To 2 Step -1
If Cells(U, 5).Value = "Blue" Or Cells(U, 5).Value = "Purple" Or Cells(U, 5).Value = "Pink" Then
Rows(U).Delete
End If
Next U

mikerickson
12-10-2007, 07:57 AM
What is happening that you don't like? (Or isn't that you do?)

Your test is case sensitive.

alivenwell
12-10-2007, 08:05 AM
Hi, yeah, i've tried to programme my code so that it deletes the row, if that cell in that column 5 (E), contains the following words:

Blue
Purple
Pink

with outrow being the last row found in my list.

but the code doesn't seem to work, i'm not sure if this is the way to write an if statement with mulitple conditions in VBA?

xld
12-10-2007, 08:13 AM
Contains or equals?

Norie
12-10-2007, 08:14 AM
alivenwell

Did you try xld's code?

The principle is that whenever deleting you work backwards.

mdmackillop
12-10-2007, 05:07 PM
Select Case is handy if you have a range of values to test.
Sub DelRows()
For U = outRow To 2 Step -1
Select Case UCase(Cells(U, 5))
Case "BLUE", "PURPLE", "PINK"
Rows(U).Delete
End Select
Next
End Sub

alivenwell
12-11-2007, 02:34 AM
Yeah, the code works.....completely bewildered that it was deleting the row and then moving on. Thanks for all your help guys.

unmarkedhelicopter
12-11-2007, 04:25 AM
You are bewildered that for a value of 5 that met your condition row 5 was deleted, making row 6, row 5 then you increment your value of 5 to 6 and are bewildered as to why the original row 6 was never tested ????