根据值选择/删除某些行

时间:2011-09-21 15:54:25

标签: excel vba excel-vba

我编写此脚本是为了删除列C中与“201103”不同的行。当我将它用于粗体时,它可以正常工作,但是当我将它与.Delete一起使用时,它表现得很奇怪并且无法正常工作。

我试图获取选定的行,而不是使用UNION合并它并使用.SELECT(多个),因此我可以手动删除它但不知道如何制作它。

Sub test()

   Dim Cell As Range

   For Each Cell In Range("C2:C2308").Cells
       If (Cell.Value <> "201103" And Cell.Value <> "") Then
           Cell.EntireRow.Font.Bold = True
           'Cell.EntireRow.Delete
       End If
   Next Cell

End Sub

有谁知道如何修复它以便它正常工作?

1 个答案:

答案 0 :(得分:3)

试试这个:

Sub test()
'

With ActiveSheet
    .AutoFilterMode = False
    With Range("C2", Range("C" & Rows.Count).End(xlUp))
        .AutoFilter 1, "<>201103"
        On Error Resume Next
        .Offset(1).SpecialCells(12).EntireRow.Delete
    End With
    .AutoFilterMode = False
End With
End Sub
相关问题