如果值在数组中,则为UDF - 类型与先前答案类型不匹配 - IsInArray

时间:2016-07-07 17:02:23

标签: arrays excel vba excel-vba

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 } 数组中。最后我想剪切单元格所在的行(如果确认在数组中)并将该行粘贴到新工作表中,但截至目前我收到的是aChecktype 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

1 个答案:

答案 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

编辑:您还应该根据需要设置搜索参数