相关疑难解决方法(0)

Worksheet类的ShowAllData方法失败

我注意到当自动过滤器已经打开时,我的VBA脚本不起作用.知道为什么会这样吗?

    wbk.Activate
    Set Criteria = Sheets("Sheet1").Cells(i, 1)

    Set rng = Sheets("Sheet1").Range(Cells(i, 2), Cells(i, 4))

    wb.Activate
    If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData 'remove autofilter, but it crashes on this line

    Selection.AutoFilter

    Range("$A$1:$BM$204").AutoFilter Field:=2, Criteria1:=Criteria.Value

    rng.Copy

    Range("$BC$2:$BE$204").SpecialCells(xlCellTypeVisible).PasteSpecial
Run Code Online (Sandbox Code Playgroud)

非常感谢

excel vba autofilter

31
推荐指数
4
解决办法
12万
查看次数

关闭过滤器

所以,我正在Excel文档中进行一些搜索,但是其他人打开过滤器并让它们保持打开是很常见的.当这些过滤器打开时,这些单元格不包含在工作表的单元格区域中.

有没有办法关闭这些自定义过滤器,以便我仍然可以到达工作表中的所有单元格?

这是我用来查找方法的方法

Microsoft.Office.Interop.Excel.Range find = sheet.Cells.Find(tapeID, Type.Missing,
Microsoft.Office.Interop.Excel.XlFindLookIn.xlValues, Microsoft.Office.Interop.Excel.XlLookAt.xlPart, 
Microsoft.Office.Interop.Excel.XlSearchOrder.xlByRows, Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext, false, Type.Missing, Type.Missing); 
Run Code Online (Sandbox Code Playgroud)

当过滤器打开时,我得到一个返回的null对象,除了关闭过滤器之外无法做任何事情,我得到了我需要的东西.

有关关闭过滤器的任何提示吗?

c# excel

10
推荐指数
1
解决办法
9984
查看次数

标签 统计

excel ×2

autofilter ×1

c# ×1

vba ×1