2017-10-24 10 views
0

私はこのquestionをかなり深く掘り下げ、Cell(r,2)を1枚のシートにマッチさせようとしました。私は関数から返されたFalse値を取得し続けます。If IsInArray(セル(r、2)、Break_List)= True Then Excel VBA

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 

から統合されている機能ですがApplication.Matchは魔法の100列目を通すするつもりはないあなたに

+0

?あなたが投稿したものは有効なコードではありません。期待される結果の代わりに現在見ているものと一緒に、サンプルデータと期待される結果を提供する必要があります。 – tigeravatar

+0

私はその機能が2D配列では機能しないと思います。各列ごとにループする必要があります。 Application.Indexを使用してhttps://www.excelforum.com/tips-and-tutorials/758402-vba-working-with-areas-within-2d-arrays.htmlショートカットを作成することができます – SJR

答えて

1

ありがとうございます。あなたが最初のカラムに通して見たい場合は、

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