2017-10-24 1 views
0

나는이 question을 매우 깊이 추종하여 Cell(r,2)을 하나의 시트에 하나의 시트에 매치 시키려고 노력했다. 시트하지만 나는 함수에서 반환 된 False 값을 계속. If IsInArray (Cells (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