View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Mike Etzkorn Mike Etzkorn is offline
external usenet poster
 
Posts: 3
Default Loops to delete rows

Ok, I did a little more research and I think I almost have it - here is the problem. The script I have deletes all the rows with a lower quantity in column "C" with duplicate information in columns "A" and "D". All that works but then the programn doesn't exit when it is done, instead I get an error, so somewhere it isn't leaving the loop, I think. I could really use some help on this one, it's almost there. Here is all the code, its kind of long

P.S. I have data several hundred rows long and 7 columns wide with lots of duplicates, if that is important

Option Explici
Public i As Range, Startingi As Range, IdenticalValues As Rang
Public Inventory As String, Brand As String, Quantity As Intege
Sub DoItAll(
SortDat
DeleteInf
End Su
Sub SortData(
Dim Total As Lon
Dim SortRange As Rang
Set SortRange = Range("A1", Range("A" & Rows.Count).
End(xlUp).Offset(0, 7).Address
SortRange.Sort Key1:=Range("D1"), Order1:=xlAscending,
Key2:=Range("A1"), Order2:=xlAscending, Key3:=Range("C1"), Order3:=xlDescending, Header:=xlYes,
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBotto
Total = SortRange.Rows.Coun
Set i = Range("A2"
End Su
Sub DeleteInfo(
Do Until i.Value = "
GetIdenticalInf
SortRangeForQuantit
DelDuplicate
Loo
End Su
Sub GetIdenticalInfo(
GetNextPair
Set Startingi =
Brand = i.Offset(0, 3).Valu
Inventory = i.Valu
Do Until Not (i = i.Offset(1) And i.Offset(0, 3) = i.Offset(1, 3)
Set i = i.Offset(1
Loo
Set IdenticalValues = Range(Startingi, i.Offset(0, 7)
If IdenticalValues.Rows.Count = 1 The
Set i = i.Offset(1
GoTo GetNextPai
End I
Set i = Starting
End Su
Sub SortRangeForQuantity(
IdenticalValues.Sort Key1:=i.Offset(0, 1), Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBotto
Quantity = i.Offset(0, 2).Valu
End Su
Sub DelDuplicates(
Do Until (i.Offset(1, 3).Value < Brand Or
i.Offset(1, 0).Value < Inventory

If i.Offset(0, 2) i.Offset(1, 2) The
i.Offset(1).EntireRow.Delet
Els
Set i = i.Offset(1
End I

Set i = i.Offset(1
Quantity = i.Offset(0, 2).Valu
Loo
Set i = Starting
End Su

Thanks for any help on this as I am doing well but this type of script is still somewhat more complicted that I am completely comfortable with

Mike Etzkor