如果IsInArray(Cells(r,2),Break_List)= True,那么Excel VBA

我一直在深深地跟踪这个问题 ,试图将一张纸上的Cell(r,2)匹配到我在下面编译的数组中循环遍历另一张纸上的第2列中的行,但是我不断收到函数返回的False值。

  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 

这是我从上面的问题中综合的function

  Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean IsInArray = Not IsError(Application.Match(stringToBeFound, arr, 0)) End Function 

谢谢

Application.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