How to find if an array contains a string使用此答案中的UDF,我试图测试C列中的每个单元格是否都在{
"error" : {
"root_cause" : [ {
"type" : "illegal_argument_exception",
"reason" : "[allocate] allocation of [abcq][0] on node {esnode2}{Pisl95VUSPmZa3Ga_e3sDA}{172.17.0.4}{172.17.0.4:9300}{master=false} is not allowed, reason: [YES(shard is primary)][YES(no allocation awareness enabled)][NO(more than allowed [90.0%] used disk on node, free: [4.078553722498398%])][YES(allocation disabling is ignored)][YES(primary shard can be allocated anywhere)][YES(node passes include/exclude/require filters)][YES(shard is not allocated to same node or host)][YES(total shard limit disabled: [index: -1, cluster: -1] <= 0)][YES(allocation disabling is ignored)][YES(no snapshots are currently running)][YES(below primary recovery limit of [4])]"
} ],
"type" : "illegal_argument_exception",
"reason" : "[allocate] allocation of [abcq][0] on node {esnode2}{Pisl95VUSPmZa3Ga_e3sDA}{172.17.0.4}{172.17.0.4:9300}{master=false} is not allowed, reason: [YES(shard is primary)][YES(no allocation awareness enabled)][NO(more than allowed [90.0%] used disk on node, free: [4.078553722498398%])][YES(allocation disabling is ignored)][YES(primary shard can be allocated anywhere)][YES(node passes include/exclude/require filters)][YES(shard is not allocated to same node or host)][YES(total shard limit disabled: [index: -1, cluster: -1] <= 0)][YES(allocation disabling is ignored)][YES(no snapshots are currently running)][YES(below primary recovery limit of [4])]"
},
"status" : 400
}
数组中。最后我想剪切单元格所在的行(如果确认在数组中)并将该行粘贴到新工作表中,但截至目前我收到的是aCheck
或type mismatch error
我尝试调试时有时使用UDF。
我将上述答案中找到的功能修改为By Ref error
,原来是ByVal arr As Range
我在本地窗口中将arr As Variant
表达式定义为acheck(aCheck_Row, 1)
,当我在本地窗口中查看表达式时,string
确实引用了列C,aSelection
表达式确实列出了工作表上的工作表值..
就像我提到的那样,我用ByVal和ByRef搞混了,并将函数中的对象从一个数组改为一个范围。我还注意到上面的答案只表明答案适用于我认为我拥有的一维阵列。
如何测试C列中的值是否在数组Values2
中,或者如果无法完成,我如何测试C列中的值是否在acheck(aCheck_Row, 1)
范围内?
aSelection
答案 0 :(得分:0)
Filter
将数组作为参数,Range
不是数组。 Range.Value
生成一个填充了范围值的箭头,但它是一个二维数组,即使范围不是(它变为(1 To 1, 1 To n)
或(1 To n, 1 To 1)
数组)。
在这种情况下最简单的解决方案是直接搜索范围
Function IsInRange(stringToBeFound As String, ByVal rng As Range) As Boolean
Dim r As Range
Set r = rng.Find(What:=stringToBeFound, _
MatchCase:=True, _
LookIn:=xlValues, _
Lookat:=xlPart) 'partial match to have the same behaviour as the filter version
If Not r Is Nothing Then IsInRange = True
End Function
编辑:您还应该根据需要设置搜索参数