1

私は顧客名の配列を持っています。この配列は重複でいっぱいであり、注文行の他のデータが異なる可能性があるため、重複する必要があります。このデータには一意の識別子がなく、1 つの注文のデータを、その顧客が配列に含まれるすべての行と比較する必要があります。

顧客が一致するすべての行を 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
4

2 に答える 2

1

うわー、とても複雑に見えます。現在の配列の隣にテーブルを作成して、次の式を使用してみましたか?

=IF(MAX(COUNTIF(A2:A11,A2:A11))>1,"Duplicates","No Duplicates")

Duplicates重複がある場合は表示され、ない場合は表示されますNo Duplicates。もちろんA2-A11から。

または、物事を本当にシンプルに保つために、条件付き書式を使用して、次のように入力できます

=COUNTIF($B$2:$B$11,B2)=1

一度しか現れない値の項目の場合。少し変更して、配列の配色を取得できます。次に、どの色が重複の数を意味するかを示すキーを側面に挿入します。

それが役立つかどうかはわかりませんが、できる限り VBA を避けるようにしています。

于 2013-11-27T08:37:16.320 に答える