Vba 如果没有',则删除单元格;不包含关键字
我有一个包含目录的列 如何搜索不包含关键字的单元格并将其删除 例如,如果我有这样一个列:Vba 如果没有',则删除单元格;不包含关键字,vba,excel,Vba,Excel,我有一个包含目录的列 如何搜索不包含关键字的单元格并将其删除 例如,如果我有这样一个列: C:\Users\Desktop\Folder\html\test.html C:\Users\Desktop\Folder\book.html C:\Users\Desktop\Folder\Documents\test.html C:\Users\Desktop\Folder\frontpage.html C:\Users\Desktop\Folder\test.html 我想搜索关键字“test.h
C:\Users\Desktop\Folder\html\test.html
C:\Users\Desktop\Folder\book.html
C:\Users\Desktop\Folder\Documents\test.html
C:\Users\Desktop\Folder\frontpage.html
C:\Users\Desktop\Folder\test.html
我想搜索关键字“test.html”,最后应该是:
C:\Users\Desktop\Folder\html\test.html
C:\Users\Desktop\Folder\Documents\test.html
C:\Users\Desktop\Folder\test.html
应删除第2行和第4行
我发现了一些有效的方法,但如果我检查整个列,则需要很长时间才能完成(因此我只使用100)
替换:
Set rng = Range("A1:A100")
与:
试试这个,它应该更快:
With UsedRange
.AutoFilter 1, "<>*test.html*", xlAnd, , False
.SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
使用UsedRange的
.AutoFilter 1,“*test.html*”,xlAnd,False
.SpecialCells(xlCellTypeVisible).EntireRow.Delete
以
处理需要时间。Like范围1到10与1到65535不同。如果这些数据在C#的内存中,那么您的性能将明显不同于通过COM组件运行代码,COM组件将excel的功能扩展到外部编程接口。或者,在您的例子中,一个惊人的应用程序(Excel)在速度不太快的编程范例上分层,在最后关闭自动筛选
,这样用户就可以真正看到他们的结果了!:)@ScottHoltzman感谢您的建议,但事实上,在我的测试中,由于VisibleDropDown:=False
参数;),所有内容在最后都变得可见我两种都试过了,但我喜欢最后一种较短的方法。不管怎样,我把最后定稿留给OP。
Set Rng = Intersect(Range("A:A"), ActiveSheet.UsedRange)
With UsedRange
.AutoFilter 1, "<>*test.html*", xlAnd, , False
.SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With