简体   繁体   English

Excel宏自动筛选和删除行

[英]Excel Macro Autofilter and Delete Rows

I am trying to get the coding below working but getting errors. 我正在尝试使下面的代码正常工作,但出现错误。

Coding selects another worksheet, then autofilter a column and delete row. 编码选择另一个工作表,然后自动过滤列并删除行。

Line having trouble is .AutoFilter 1, " NoNo " 遇到麻烦的行是.AutoFilter 1,“ NoNo

Run-time error '1004': AutoFilter method of Range clas failed. 运行时错误'1004':Range clas的AutoFilter方法失败。

Can I please get some assistance. 请给我一些帮助。

Private Sub Project()
Worksheets("YesYes").Select
With ActiveSheet
.AutoFilterMode = False
 With Range("y1", Range("y" & Rows.Count).End(xlUp))
    .AutoFilter 1, "*NoNo*"
    On Error Resume Next
    .Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
End Sub

Selecting does not necessarily "Activate" the worksheet. 选择不一定“激活”工作表。 Instead of: 代替:

Worksheets("YesYes").Select
With ActiveSheet

Do this: 做这个:

Worksheets("YesYes").Activate
With ActiveSheet

99% of the times using Select or Activate is not necessary. 不需要99%的时间使用“ Select或“ Activate

Instead use fully qualified objects, in your case use: 在您的情况下,请使用完全合格的对象:

With Worksheets("YesYes")

And nested below use: 并嵌套在下面使用:

With .Range("y1", .Range("y" & .Rows.Count).End(xlUp))

And then add the rest of your code. 然后添加其余的代码。

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

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