开发者

Selecting/deleting certain rows depending on value

I wrote this script to delete rows which contain a value in column C that is different than "201103". When I use this to bold it, it works, but when I use it with .Delete it behaves strange and does not work properly.

I was trying to get selected rows and than use UNION to merge it and use .SELECT (multiple) so I could delete it manually but not sure how to make it.

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.Delet开发者_StackOverflowe
       End If
   Next Cell

End Sub

Does anyone know how to fix it so it works fine?


Try this:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜