1

我一直在使用这个网站一段时间,并且一直在寻找一种相对简单的方法来在 Excel 07 中实现 VBA 中的任务。

我有一列有许多不同的值,我试图在 AA:AA 中找到以“L-”开头的单元格,然后从那里删除工作表中的行。activesheet/activebook 永远不会改变,但我遇到的问题是该列不时有空白单元格。我试过使用下面的代码,但我没有达到我需要的结果。

Sub Remove_Expendables()
Application.ScreenUpdating = FALSE
Range("AA1").Select
Do
ActiveCell.Offset(1, 0).Select
If ActiveCell = (Left("L-",2) Then ActiveCell.ClearContents
Loop Until IsEmpty(ActiveCell.Offset(0, 2))
ActiveSheet.Columns("AA:AA").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Application.ScreenUpdating = TRUE
End Sub
4

2 回答 2

1

AutoFilter比循环快得多。

Sub AF_Delete()
    Application.ScreenUpdating = False
    With ActiveSheet
        .AutoFilterMode = False
        .Columns("AA").AutoFilter Field:=1, Criteria1:="=L-*"
        .AutoFilter.Range.Offset(1, 0).EntireRow.Delete        '
        .AutoFilterMode = False
    End With
    Application.ScreenUpdating = True
End Sub
于 2013-07-18T19:32:50.950 回答
0
Sub Remove_Expendables()
Dim c as range, rngDel as range
set c= activesheet.cells(rows.count, "AA").end(xlup)

Application.ScreenUpdating = FALSE
Do While c.row > 1
    If c.value like "L-*" Then
        if rngDel is nothing then
            set rngDel=c
        else
            set rngDel=application.union(rngDel,c)
        end if
    end if
    set c=c.offset(-1,0)
Loop 
if not rngDel is nothing then rngDel.entirerow.delete
Application.ScreenUpdating = TRUE
End Sub
于 2013-07-18T18:29:35.093 回答