Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
Run time error 1004, General ODBC error [email protected] New Users to Excel 0 September 19th 05 01:41 AM
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) Tim[_36_] Excel Programming 4 April 23rd 04 02:53 AM
Run-time error '11' & Run-time error '1004' Piers Clinton-Tarestad Excel Programming 0 January 9th 04 08:35 PM
Run-time error '11' & Run-time error '1004' Piers Clinton-Tarestad Excel Programming 0 January 9th 04 07:45 PM


All times are GMT +1. The time now is 11:01 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"