我一直非常关注这个question并试图将Cell(r,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 IsInArray(stringToBeFound As String, arr As Variant) As Boolean
IsInArray = Not IsError(Application.Match(stringToBeFound, arr, 0))
End Function
谢谢
答案 0 :(得分:1)
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