【发布时间】:2019-05-17 14:36:45
【问题描述】:
我正在尝试使用 VBA 在 Excel 数据透视表中过滤过滤器,但该过程花费了大量时间。用户在文本框中键入并单击提交按钮以开始操作。我的过滤器有超过 2.000 个值。这是我在这种情况下使用的代码。
是否存在最快的过滤方式?
Sub a()
Dim txt1 As String
txt1 = Worksheets("Planilha1").TextBox1.Value
If Not txt1 = "" Then
Set ws = Sheets("Planilha1")
Set pt = ws.PivotTables(1)
Set pf = pt.PageFields(1)
For Each Pi In pf.PivotItems
If Not Pi = txt1 Then
pf.PivotItems(CStr(Pi)).Visible = False
End If
Next Pi
End If
End Sub
【问题讨论】:
-
你有没有试过 Application.ScreenUpdating = False 在循环之前和 Application.ScreenUpdating = True 在循环之后?也许是导致问题的渲染
-
不,我没有尝试。但是我看到这个问题是关于它的(渲染)。你的答案和下面的答案对我有用!谢谢你:)
标签: excel vba filter pivot-table