Run-time error

L

ljCharlie

Here's the code:

If U.Cells(i).Value = "Yes" Then
Selection.Rows(i).EntireRow.Delete
End If

I'm trying to compare the cell value in column U to see if it equals
the word "Yes" and if it is, delete the whole entire row. The error was
Run-time error 424 Object require at the above code.

Any suggestion is apreciated.

ljCharlie
 
C

Chip Pearson

Charlie,

Try something like

If Cells(i,"U").Value = "Yes" Then
Rows(i).Delete
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
L

ljCharlie

Many thanks for your help. The error is gone...but still hasn't done
what I wanted to do yet. Here's the whole code.


Sub deleteDupRow()
Dim Q As Range
Dim x As String
Set Q = Range("Q1:Q20")

With Application
Calculation = xlCalculationManual
ScreenUpdating = False
For i = 1 To Q.Rows.Count
x = Q.Rows.Cells(i)
If x = "Yes" Then
Rows(i).Delete
End If
Next i
End With

End Sub


The problem I have now is that the rows(i).delete did not delete the
correct row. In addition, even if the comparison x="Yes", it's not
deleting the row.

Any idea why this behavior?

ljCharlie
 
C

Chip Pearson

When you are deleting rows in a loop, you need to start at the
bottom and work your way up. For example,


For i = Q.Rows.Count To 1 Step -1
x = Q.Rows.Cells(i)
If x = "Yes" Then
Rows(i).Delete
End If
Next i


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Top