ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run-time error (https://www.excelbanter.com/excel-programming/298173-run-time-error.html)

ljCharlie[_11_]

Run-time error
 
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


---
Message posted from http://www.ExcelForum.com/


Chip Pearson

Run-time error
 
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



"ljCharlie " wrote in
message ...
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


---
Message posted from http://www.ExcelForum.com/




ljCharlie[_12_]

Run-time error
 
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


---
Message posted from http://www.ExcelForum.com/


Chip Pearson

Run-time error
 
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



"ljCharlie " wrote in
message ...
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


---
Message posted from http://www.ExcelForum.com/




ljCharlie[_13_]

Run-time error
 
Many thanks to you. It works! I just add one line to it and it works.

ljCharli

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 07:23 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com