VBA: How to delete filtered rows in Excel?

后端 未结 2 1597
无人及你
无人及你 2020-12-01 16:15

I have an Excel table that contains some data. By using next vba code I\'m trying to filter only blank cells in some fields and delete these rows

ActiveSheet         


        
2条回答
  •  执笔经年
    2020-12-01 16:59

    As an alternative to using UsedRange or providing an explicit range address, the AutoFilter.Range property can also specify the affected range.

    ActiveSheet.AutoFilter.Range.Offset(1,0).Rows.SpecialCells(xlCellTypeVisible).Delete(xlShiftUp)
    

    As used here, Offset causes the first row after the AutoFilter range to also be deleted. In order to avoid that, I would try using .Resize() after .Offset().

提交回复
热议问题