고객 이름 배열이 있습니다. 이 어레이는 중복으로 가득 차며 주문 행의 다른 데이터가 다를 수 있기 때문에 필요합니다. 이 데이터에 대한 고유 식별자가 없으므로 배열의 해당 고객을 보유하고있는 모든 행과 한 주문의 데이터를 비교해야합니다.중복 값이있는 배열에서 값 찾기
for 루프가 고객과 일치하는 모든 행을 검색하는 데 문제가 있습니다.
도움이 될 것입니다.
Dim prodlog As String
Dim orddate As Variant
Dim cus As String
Dim owner As String
Dim orddate2 As Variant
Dim owner2 As String
Dim LogCusts As Variant
LogCusts = Application.Transpose(Range("F3", Range("F" & Rows.count).End(xlUp)))
Dim loglen As Integer
loglen = UBound(LogCusts) - LBound(LogCusts)
Dim cust2 As Variant
For Each cust2 In LogCusts
Dim custrow As Integer
custrow = Application.Match(cust2, LogCusts, False) + 1
prodlog = Range(Cells(custrow, 5), Cells(custrow, 5)).Value
orddate = Range(Cells(custrow, 2), Cells(custrow, 2)).Value
cus = Range(Cells(custrow, 6), Cells(custrow, 6)).Value
owner = Range(Cells(custrow, 7), Cells(custrow, 7)).Value
databook.Activate
logjam.Select
orddate2 = Range(Cells(custrow + 1, 5), Cells(custrow + 1, 5)).Value
owner2 = Range(Cells(custrow + 1, 7), Cells(custrow + 1, 7)).Value
If IsEmpty(orddate) Then
Exit For
End If
If IsEmpty(prodlog) Then
trackbook.Activate
masterlog.Select
Range(Cells(custrow, 2), Cells(custrow, 17)).Clear
Else: While cus = cust2
If orddate = orddate2 And owner = owner2 Then
Range(Cells(custrow, 8), Cells(custrow, 8)).Value = prodlog
End If
Wend
End If
Next cust2
다음은 Scripting.Dictionary를 사용하는 방법입니다. http://stackoverflow.com/a/11870350/2258 –