Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default Delete Entire Row

Hi all, I have macro to delete Entire Rows the one have "X" in column
A (see macro below).

Sub DelRow()
Dim c As Range
For Each c In Range("A1:A500").Cells
If c.Value = "X" Then
c.EntireRow.Delete
End If
Next c
End Sub

The problem I am having that macro don’t delete all those rows the one
have character "X" in column A. I have to run macro more than one
time to delete all rows. Please can any friend can help that how can
I achive my goal just running macro once.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Delete Entire Row

Hi,

You have to loop backwards through the range

Sub DelRow()
Dim c As Range
For x = 500 To 1 Step -1
If Cells(x, 1).Value = "X" Then
Rows(x).EntireRow.Delete
End If
Next
End Sub

Mike

"K" wrote:

Hi all, I have macro to delete Entire Rows the one have "X" in column
A (see macro below).

Sub DelRow()
Dim c As Range
For Each c In Range("A1:A500").Cells
If c.Value = "X" Then
c.EntireRow.Delete
End If
Next c
End Sub

The problem I am having that macro dont delete all those rows the one
have character "X" in column A. I have to run macro more than one
time to delete all rows. Please can any friend can help that how can
I achive my goal just running macro once.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Delete Entire Row

Hi,

Here's a method of going forward through the range doing the same thing on
the used range of column A instead of using a fixed A1 - A500

Sub Please_Delete_Me()
Dim copyrange As Range, lastrow As Long
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set myRange = Range("A1:A" & lastrow)
For Each c In myRange
If c.Value = "X" Then
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.Delete
End If
End Sub

Mike

"Mike H" wrote:

Hi,

You have to loop backwards through the range

Sub DelRow()
Dim c As Range
For x = 500 To 1 Step -1
If Cells(x, 1).Value = "X" Then
Rows(x).EntireRow.Delete
End If
Next
End Sub

Mike

"K" wrote:

Hi all, I have macro to delete Entire Rows the one have "X" in column
A (see macro below).

Sub DelRow()
Dim c As Range
For Each c In Range("A1:A500").Cells
If c.Value = "X" Then
c.EntireRow.Delete
End If
Next c
End Sub

The problem I am having that macro dont delete all those rows the one
have character "X" in column A. I have to run macro more than one
time to delete all rows. Please can any friend can help that how can
I achive my goal just running macro once.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default Delete Entire Row

On Mar 3, 3:24*pm, Mike H wrote:
Hi,

Here's a method of going forward through the range doing the same thing on
the used range of column A instead of using a fixed A1 - A500

Sub Please_Delete_Me()
Dim copyrange As Range, lastrow As Long
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set myRange = Range("A1:A" & lastrow)
For Each c In myRange
* * If c.Value = "X" Then
* * * * If copyrange Is Nothing Then
* * * * * * * * Set copyrange = c.EntireRow
* * * * Else
* * * * * * * * Set copyrange = Union(copyrange, c.EntireRow)
* * * * End If
* * End If
Next
If Not copyrange Is Nothing Then
copyrange.Delete
End If
End Sub

Mike



"Mike H" wrote:
Hi,


You have to loop backwards through the range


Sub DelRow()
Dim c As Range
For x = 500 To 1 Step -1
If Cells(x, 1).Value = "X" Then
Rows(x).EntireRow.Delete
End If
Next
End Sub


Mike


"K" wrote:


Hi all, *I have macro to delete Entire Rows the one have "X" in column
A (see macro below).


Sub DelRow()
Dim c As Range
For Each c In Range("A1:A500").Cells
If c.Value = "X" Then
c.EntireRow.Delete
End If
Next c
End Sub


The problem I am having that macro don’t delete all those rows the one
have character "X" in column A. *I have to run macro more than one
time to delete all rows. *Please can any friend can help that how can
I achive my goal just running macro once.- Hide quoted text -


- Show quoted text -


Thats great. Thanks guys
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Delete Entire Row

When deleting rows, it is better to start from the bottom and work up
Sub DelRow()
Dim c As Integer
For c = 500 to 1 step -1
If cells(c,1).Value = "X" Then
activesheet.rows(c).delete
End If
Next c
End Sub


"K" wrote in message
...
Hi all, I have macro to delete Entire Rows the one have "X" in column
A (see macro below).

Sub DelRow()
Dim c As Range
For Each c In Range("A1:A500").Cells
If c.Value = "X" Then
c.EntireRow.Delete
End If
Next c
End Sub

The problem I am having that macro don’t delete all those rows the one
have character "X" in column A. I have to run macro more than one
time to delete all rows. Please can any friend can help that how can
I achive my goal just running macro once.




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
Delete an entire row One-Leg Excel Discussion (Misc queries) 13 November 11th 08 08:27 PM
Delete Entire Row if value is not Q Sean Excel Programming 16 February 7th 07 02:06 PM
Delete Entire Row Corey Excel Programming 4 February 6th 07 12:24 AM
Need to delete last value in column but not delete entire row [email protected] Excel Programming 4 October 19th 06 05:26 PM
Another delete entire row Sean[_9_] Excel Programming 1 May 11th 04 04:41 PM


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

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

About Us

"It's about Microsoft Excel"