【问题标题】:VBA Autofilter - delete only visible cells within table and not the entire rowVBA Autofilter - 仅删除表格中的可见单元格而不是整行
【发布时间】:2018-09-14 14:29:19
【问题描述】:

我正在使用自动过滤器快速删除空行,但我认为我可以仅使用delete(xlshiftup) 而不是entirerow.delete 来设法仅删除当前范围内的单元格而不是整行

下面的代码是我用过的:

With Range
    .AutoFilter Field:=1, Criteria1:="="
    .offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Delete (xlShiftUp)
End with

这可能吗?我认为这将是解决方案,但由于某种原因,它会删除剩余可见行中的所有内容。

【问题讨论】:

  • 如何设置初始Range?它有多少列宽? (在删除前贴MsgBox "Now deleting " & cstr(.Columns.Count) & " columns from " & cstr(.Rows.Count-1) & " rows"以获得提醒)

标签: vba autofilter


【解决方案1】:

引用过滤范围,删除自动过滤并删除引用范围:

With Range
    .AutoFilter Field:=1, Criteria1:="="
    With .Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
        .Parent.AutoFilterMode = False
        .Delete (xlShiftUp)
    End With
End With

【讨论】:

  • 像魅力一样工作!不敢相信我不知道.parent 运算符
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-07-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多