Arrays 如果IsInArray(单元格(r,2),Break_List)=True,则Excel VBA

Arrays 如果IsInArray(单元格(r,2),Break_List)=True,则Excel VBA,arrays,vba,excel,excel-2010,Arrays,Vba,Excel,Excel 2010,我一直在非常深入地关注这一点,并试图将一张工作表上的Cellr,2与我在下面编译的数组进行匹配,在另一张工作表上循环遍历第2列中的行,但我一直从函数返回一个假值 Public Break_List(1 To 1000, 1 To 100) As Variant If IsInArray(Cells(r, 2), Break_List) = True Then Sub Store_Break_Categories() Sheets("BackEnd").Sele

我一直在非常深入地关注这一点,并试图将一张工作表上的Cellr,2与我在下面编译的数组进行匹配,在另一张工作表上循环遍历第2列中的行,但我一直从函数返回一个假值

    Public Break_List(1 To 1000, 1 To 100) As Variant

    If IsInArray(Cells(r, 2), Break_List) = True Then

    Sub Store_Break_Categories()
    Sheets("BackEnd").Select
    Break_No_of_Rows = 0
    'For c = 10 To 15
    counter = 0
        If Cells(2, 3) <> "" Then
        lastrow = Cells(65000, 3).End(xlUp).Row
           For r = 2 To lastrow
              counter = counter + 1
               'Break_List(counter, c - 9) = Cells(r, c)
                  Break_List(counter, 1) = Cells(r, 3)
           Next r
        End If
        If counter > Break_No_of_Rows Then Break_No_of_Rows = counte
    End Sub

谢谢应用程序。Match不会神奇地浏览100列。如果你想看第一列

Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean
    IsInArray = Not IsError(Application.Match(stringToBeFound, Application.Index(arr, 0, 1), 0))
End Function
如果你想浏览所有的栏目

Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean
    dim a as long
    IsInArray = false
    for a = lbound(arr, 2) to ubound(arr, 2)
        If Not IsError(Application.Match(stringToBeFound, Application.Index(arr, 0, a), 0)) then
            IsInArray = true
            exit function
        end if
    next a
End Function

?? 您发布的代码无效。您还需要提供示例数据和预期结果,以及您当前看到的结果,而不是预期结果。我认为该函数在2D数组上不起作用。您必须循环浏览每一列。您可以使用Application.Index创建快捷方式
Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean
    dim a as long
    IsInArray = false
    for a = lbound(arr, 2) to ubound(arr, 2)
        If Not IsError(Application.Match(stringToBeFound, Application.Index(arr, 0, a), 0)) then
            IsInArray = true
            exit function
        end if
    next a
End Function