Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Macro does not delete all the required rows

Hi Everyone,

I have a datasheet (a daily report that I get from a system). In this
report I have column AE that contains the identifier for that row.
Some of the identifiers are DUMMY. These are wrong postings from the
system. I have written a following code to delete all rows that have
DUMMY in column AE.

Sub delete_dummy()
Dim Cell As Range
For each Cell in Range("AE:AE")
If Cell.Value = "DUMMY" Then
Cell.EntireRow.Delete
End If
Next Cell
End Sub

The code works but it does not delete all the rows containing dummy. I
have to run it a few times before all the dummy rows are deleted. I
have no idea why that happens and how to fix it so that all the dummy
items are deleted in one go. Can someone help me with this. Thanks
very much.

Regards,
-AG
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Macro does not delete all the required rows

You need to start at the bottom and work to the top
when deleting multiple row. It automatically shifts
up after deleting the row so that you skip rows if you
go top to bottom. Try this.

Sub delete_dummy()
Dim i As Range, lstRow As Long
LstRow = Cells(Rows.Count, 31).End(xlUp).Row
sRng = Range("AE1:AE" & lstRow)
For i = lstRow To 1 Step *1
If i.Value = "DUMMY" Then
i.EntireRow.Delete
End If
Next
End Sub



"AG" wrote:

Hi Everyone,

I have a datasheet (a daily report that I get from a system). In this
report I have column AE that contains the identifier for that row.
Some of the identifiers are DUMMY. These are wrong postings from the
system. I have written a following code to delete all rows that have
DUMMY in column AE.

Sub delete_dummy()
Dim Cell As Range
For each Cell in Range("AE:AE")
If Cell.Value = "DUMMY" Then
Cell.EntireRow.Delete
End If
Next Cell
End Sub

The code works but it does not delete all the rows containing dummy. I
have to run it a few times before all the dummy rows are deleted. I
have no idea why that happens and how to fix it so that all the dummy
items are deleted in one go. Can someone help me with this. Thanks
very much.

Regards,
-AG

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Macro does not delete all the required rows

I know better than that. Use this:

Sub delete_dummy()
Dim i As Range, lstRow As Long
LstRow = Cells(Rows.Count, 31).End(xlUp).Row
For i = lstRow To 1 Step -1
IfCells( i, 31).Value = "DUMMY" Then
Cells(i, 31).EntireRow.Delete
End If
Next
End Sub



"AG" wrote:

Hi Everyone,

I have a datasheet (a daily report that I get from a system). In this
report I have column AE that contains the identifier for that row.
Some of the identifiers are DUMMY. These are wrong postings from the
system. I have written a following code to delete all rows that have
DUMMY in column AE.

Sub delete_dummy()
Dim Cell As Range
For each Cell in Range("AE:AE")
If Cell.Value = "DUMMY" Then
Cell.EntireRow.Delete
End If
Next Cell
End Sub

The code works but it does not delete all the rows containing dummy. I
have to run it a few times before all the dummy rows are deleted. I
have no idea why that happens and how to fix it so that all the dummy
items are deleted in one go. Can someone help me with this. Thanks
very much.

Regards,
-AG

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Macro does not delete all the required rows

Hi JLGWhiz,
Thanks very much for the help. It works fine. I think you meant
i As Integer and not Range.

I will be interested to know why it does not work when you go from top
to bottom. I am sure you would know.
Thanks again for your help.

Regards,
-AG
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
Macro to delete rows Hankjam[_2_] Excel Discussion (Misc queries) 4 October 1st 08 03:58 PM
Can't get Rows to delete in macro Goobies[_7_] Excel Programming 2 February 2nd 06 08:05 AM
Macro to delete rows Melanie Breden Excel Programming 2 May 10th 04 11:16 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Excel Programming 4 May 3rd 04 08:45 PM


All times are GMT +1. The time now is 11:16 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"