删除行并向上移动多个单词

时间:2018-03-07 03:20:10

标签: database excel vba

我想找到一种方法来删除所有行并向上移动单元格。

该列包含各种单词。其中我想删除一些单词(例如" GT"," ST"," Food" - 共10个不同的单词)。感谢您的建议。

1 个答案:

答案 0 :(得分:1)

对AutoFilter条件使用单词数组。

dim crit as variant
crit = array("GT", "ST", "Food")
with worksheets("sheet1")
    if .autofiltermode then .autofiltermode = false
    with .cells(1, 1).currentregion
        .autofilter field:=1, criteria1:=crit, operator:=xlfiltervalues
        with .resize(.rows.count-1, .columns.count).offset(1, 0)
            if cbool(application.subtotal(103, .cells)) then
                .specialcells(xlcelltypevisible).entirerow.delete
            end if
        end with
    end with
    if .autofiltermode then .autofiltermode = false
end with