0
我有一个宏,它根据项目#(列A)取出垃圾销售。正如您在下面的代码中看到的,有很多垃圾(需要删除的行)项目编号以“40-xxxxx”开头。我想结合这些循环,以便宏将删除以“40-xxxxx”开头的所有项目#除外“40-00017”&“40-00004”。结合多个For While While循环提高效率vba
sItem = Cells(I, 1)
Do While Left(sItem, 8) = "40-00087" 'labor-annual refinish
Rows(I).Select
Selection.Delete shift:=xlUp
sItem = Cells(I, 1)
Loop
Next I
For I = 2 To nRowMax
sItem = Cells(I, 1)
Do While Left(sItem, 8) = "40-00076" 'CONNOISSEURS CLOTH
Rows(I).Select
Selection.Delete shift:=xlUp
sItem = Cells(I, 1)
Loop
Next I
For I = 2 To nRowMax
sItem = Cells(I, 1)
Do While Left(sItem, 8) = "40-00007" 'labor jewelery
Rows(I).Select
Selection.Delete shift:=xlUp
sItem = Cells(I, 1)
Loop
Next I
For I = 2 To nRowMax
sItem = Cells(I, 1)
Do While Left(sItem, 8) = "40-00073" 'foam cleaner blitz
Rows(I).Select
Selection.Delete shift:=xlUp
sItem = Cells(I, 1)
Loop
Next I
For I = 2 To nRowMax
sItem = Cells(I, 1)
Do While Left(sItem, 8) = "40-00084" 'labor-razny 1st
Rows(I).Select
Selection.Delete shift:=xlUp
sItem = Cells(I, 1)
Loop
Next I
For I = 2 To nRowMax
sItem = Cells(I, 5)
Do While Left(sItem, 2) = "GC" 'gift cards
Rows(I).Select
Selection.Delete shift:=xlUp
sItem = Cells(I, 5)
Loop
Next I
不得不说,尽管用@ Coffeegrinder的方法(只要你没有任何空白行)。 – SJR