简体   繁体   English

删除范围内具有特定文本的单元格

[英]Delete cells with specific text on a range

I have a range up that's 5k or so cells and I want to remove the cells that has specific texts on it.我有一个大约 5k 个单元格的范围,我想删除上面有特定文本的单元格。 IE And, a, is, that, or, with, the, etc. Is there a way to this? IE And, a, is, that, or, with, the, etc. 有没有办法做到这一点? Please help.请帮忙。

[A2].Select
Range("A2", Selection.End(xlDown)).Select

Dim crnge As Range
Dim wdelim
Dim rdelim

wdelim = Split("on,the,this,in,at,of,for,what,w,all,on,with", ",")

Set crnge = Selection

For Each rdelim In wdelim
    crnge.wdelim.Select
    .Delete (xlUp)
Next

I know this code doesn't work, this is just what I'm trying to do but I'm not sure how to do it.我知道这段代码不起作用,这正是我想要做的,但我不知道该怎么做。

Here I filter the data for each element in the array and delete all the entire row of visible cells.在这里,我过滤数组中每个元素的数据并删除所有可见单元格的整行。

Sub DeleteFilteredRows()
    Dim v
    With Application
        .ScreenUpdating = False
        .Calculation = xlCalculationManual
    End With

    For Each v In Split("on,the,this,in,at,of,for,what,w,all,on,with", ",")
        With Range("A1").CurrentRegion
            On Error Resume Next
            'If you want all rows that have any of this phrases anywhere in
            'the cell use: Criteria1:="=*" & v & "*"                             

            .AutoFilter Field:=1, Criteria1:="=" & v , Operator:=xlAnd
            .Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
            On Error GoTo 0
            .AutoFilter

        End With

    Next

    With Application
        .ScreenUpdating = True
        .Calculation = xlCalculationAutomatic
    End With
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM