vba - VBA - 自动过滤器数组中的连接字符串不起作用
问题描述
因此,我将所有变量存储在一个字符串中,然后尝试将其传递给 Autofilter 标准,但无济于事。
Sub TestAutoFilter()
'Filter based on column Importance.
'PURPOSE: Dynamically Create Array Variable based on a Given Size
Dim myArray() As Variant
Dim DataRange As Range
Dim cell As Range
Dim x As Long
'Determine the data you want stored
Set DataRange = ActiveSheet.UsedRange
'Resize Array prior to loading data
'Loop through each cell in Range and store value in Array
counter = 0
For Each chkbx In ThisWorkbook.Sheets("Sheet1").CheckBoxes
If chkbx.Value > 0 And InStr(1, LCase(chkbx.Name), "check") <> 0 Then
counter = counter + 1
End If
Next chkbx
ReDim myArray(counter)
For Each chkbox In ThisWorkbook.Sheets("Sheet1").CheckBoxes
If chkbox.Value > 0 And InStr(1, LCase(chkbox.Name), "check") <> 0 Then
myArray(x) = chkbox.Caption
x = x + 1
End If
Next chkbox
myArrayString = ""
'Print values to Immediate Window (Ctrl + G to view)
For x = LBound(myArray) To counter
myArrayString = myArrayString & "," & myArray(x)
Next x
'Debug.Print (myArrayString)
myRightString = Left(myArrayString, Len(myArrayString) - 1)
myLeftString = Right(myRightString, Len(myRightString) - 1)
'Debug.Print (RTrim(myLeftString))
ThisWorkbook.Sheets("Data").Range("A3:F3").AutoFilter Field:=3, _
Criteria1:=Array(myLeftString), _
Operator:=xlFilterValues
End Sub
我还尝试将 myLeftstring 替换为实际的数组,Criteria1:=myArray
但这也没有用。
解决方案
推荐阅读
- c - 从 C 环境执行 shell 命令并重定向输出
- objective-c - 在 Xcode 中使用 Objective-C 初始化 NSWindowController 时出现“缺少 setter 或实例变量”日志消息:
- javascript - 如何仅使用本地 json 文件或网络服务器中的 javascript 显示 json 数据?
- xamarin - 如何为 Xamarin Forms 中的特定页面使用不同的主题?
- spring - 关于 HEADERS 的 Spring Integration HttpRequestExecutingMessageHandler 问题
- jquery - 当用户单击发送按钮时,从 twitter 引导模式传递值
- c# - Asp.Net MVC 5 测试 IoC + 依赖注入
- css - 如何在没有弹性盒的情况下使图像使用最佳空间量
- javascript - 无法使用 PHP 执行查询,其中相同的查询在 phpmyadmin 中可以正常工作
- typescript - Redux 4.0 中存储增强器的 TypeScript 输入问题