已编辑以修复拼写错误并添加更多详情
我想你可以在这里看到我想做的事情:
Dim bMatch As Boolean
Dim vCriteria As Variant
Dim rCell As Range
Dim vCellArray() As Variant
If rCell = "" Then
'Do nothing
Else
For Each vCriteria In vCriteriaArray
If InStr(1, rCell, ",") Then
ReDim vCellArray(0 To Len(rCell) - Len(Replace(rCell, ",", "")))
vCellArray = CVar(Split(rCell, ","))
Else
ReDim vCellArray(0 To 0)
vCellArray(0) = rCell
End If
If UBound(Filter(vCellArray, vCriteria)) > -1 Then
bMatch = True
Exit For
End If
Next vCriteria
If bMatch = False Then
rCell.EntireRow.Hidden = True
End If
End If
Next rCell
我想从rCell中读取内容,根据逗号分隔符将其拆分并将其存储在变量数组中。
然而声明
vCellArra = CVar(Split(rCell, ","))
如果在之前发生以下陈述,则停止工作
ReDim vCellArray(0 To 0)
vCellArray(0) = rCell
我尝试了ReDimin数组
ReDim vCellArray(0 To Len(rCell) - Len(Replace(rCell, ",", "")))
但这没有帮助。
如何更改代码以便我可以完成我的目标“从rCell读取内容,根据逗号分隔符将其拆分并将其存储在变量数组中”,无论是否存在在rCell中是否有逗号?
答案 0 :(得分:1)
这似乎只相当于:
If rCell = "" Then
'Do nothing
Else
For Each vCriteria In vCriteriaArray
If InStr(1, "," & rCell.Value & ",", "," & vCriteria & ",", vbTextCompare) <> 0 Then
bMatch = True
Exit For
End If
Next vCriteria
If Not bMatch Then rCell.EntireRow.Hidden = True
End If