View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett[_4_] Don Guillett[_4_] is offline
external usenet poster
 
Posts: 2,337
Default Loops to delete rows

when deleting rows it is best to work from the bottom up with
for i=100 to 1 step -1
next

--
Don Guillett
SalesAid Software

"Mike Etzkorn" wrote in message
...
Here is a quick version of the situation. I have a file with 7 columns of

data and I sort it with a script. Then I have another script that goes
through and deletes files based on a certain paramenter. If the value in
"A1" = "A2" and "D1" = "D2" then delete the row "2" as long as the value in
"C2" is less than the value in "C1" - then contine on throught the entire
range deleting rows.

So far the sort works and I think I am close on the loop - using two books

and info found in here - but I am not sure whats wrong and why it isn't
working right. Here's the code I have so far:

Option Explicit
Public i As Range, Startingi As Range
Public Brand As String, Type As String, Quantity As Integer

Sub DeletePairs()
Dim SortRange As Range
Set SortRange = Range("A1", Range("A" &

Rows.Count).End(xlUp).Offset(0, 7). _
Address)
Set Startingi = i
Type = i.Value
Brand = i.Offset(0, 1).Value
Do While Not (i.Offset(0, 0) = i.Offset(1, 0) & i.Offset(0, 1) =

i.Offset(1, 1))
If i.Offset(0, 2) i.Offset(1, 2) Then
i.Offset(1).EntireRow.Delete
End If
Loop
End Sub

I am new to this type of scripting, I really only know the basics - so I

am not sure if I am even on the right path - It only what I have sort of
pieced together so far.

Any help would be greatly appreciated, because the frustration level is

starting to get high
Mike Etzkorn