Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Delete an entire row | Excel Discussion (Misc queries) | |||
Delete Entire Row if value is not Q | Excel Programming | |||
Delete Entire Row | Excel Programming | |||
Need to delete last value in column but not delete entire row | Excel Programming | |||
Another delete entire row | Excel Programming |