顧客と生年月日の列が行間で一致する場合は、収益を合計します。VBAでの行の整理
account number customer Date of Birth Country $ Revenue StartD
47971 MARTY-ANE 27/12/1957 IF_FR_OU 100 10022010
48045 QUESNEL 06/05/1956 IF_FR_OU 200 11022010
47999 MARTY-ANE 27/12/1957 IF_IT_OU 100 12022010
私は次のようになりたい:
account number customer Date of Birth Country $ Revenue StartD
47971 & 47999 MARTY-ANE 27/12/1957 IF_FR_OU 200 10022 & 12022
48045 QUESNEL 06/05/1956 IF_FR_OU 200 11022
コード:
Sub ProcessCustomers()
Dim key As Variant, values As Variant, results As Variant
Dim list As Object
Dim x As Long, IndexOf As Long
Set list = CreateObject("System.Collections.ArrayList")
'account number|customer|Date of Birth|Country|$ Revenue
With Worksheets("Sheet1")
For x = 2 To .Range("A" & .Rows.Count).End(xlUp).Row
key = .Cells(x, 2).Value & "|" & .Cells(x, 3).Value & "|" &
.Cells(x, 4).Value
If list.Count = 0 Then ReDim results(0 To 4, 0 To 0)
If list.Contains(key) Then
IndexOf = list.LastIndexOf(key)
results(0, IndexOf) = results(0, IndexOf) & " & " &
.Cells(x, 1).Value
results(4, IndexOf) = results(4, IndexOf) + .Cells(x,
5).Value
Else
list.Add key
ReDim Preserve results(0 To 4, 0 To list.Count - 1)
IndexOf = list.Count - 1
results(0, IndexOf) = .Cells(x, 1).Value
results(1, IndexOf) = .Cells(x, 2).Value
results(2, IndexOf) = .Cells(x, 3).Value
results(3, IndexOf) = .Cells(x, 4).Value
results(4, IndexOf) = .Cells(x, 5).Value
End If
Next
End With
'Transpose results and change the Array Base from 0 to 1
results = Application.Transpose(results)
With Worksheets.Add
.Range("A1").Resize(1, 5).Value = Split("account
number|customer|Date of Birth|Country|$ Revenue", "|")
.Range("A1").Resize(UBound(results), UBound(results, 2)).Value =
results
End With
End Sub
と質問は.......... ?? –
私の元のコードは収入までマージしていますが、開始Dは含まれていません。私は範囲を広げようとしましたが、私はこの仕事をするために何をする必要がありますか? –