如果客戶和出生日期列在行之間匹配,我想總結收入。在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,我試過增加範圍,但沒有工作,我需要做什麼來得到這項工作? –