Hi
Have data with multiple columns with
col-A Cus-Name
col-B InVoice-No
col-C First Bill-Amount
col-D Second Bill-Amount
i have applied this below VBA to Sum and Delete Rows here my problem is it's not giving result has i expect
This is data i have
i want like this
Have data with multiple columns with
col-A Cus-Name
col-B InVoice-No
col-C First Bill-Amount
col-D Second Bill-Amount
i have applied this below VBA to Sum and Delete Rows here my problem is it's not giving result has i expect
This is data i have
MMM.xlsm | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | Cus-Name | InVoice-No | First Bill-Amount | Second Bill-Amount | ||
2 | Raju.M | BVSI-001 | 250.75 | 425.98 | ||
3 | Raju.M | BVSI-001 | 450.25 | 284.65 | ||
4 | Raju.M | BVSI-001 | 321.45 | 674.25 | ||
5 | Raju.M | BVSI-001 | 458.32 | 954.65 | ||
6 | Swathi.P | BVSI-002 | 250.75 | 742.65 | ||
7 | Swathi.P | BVSI-002 | 450.25 | 248.65 | ||
8 | Swathi.P | BVSI-002 | 321.45 | 485.39 | ||
9 | Swathi.P | BVSI-002 | 458.32 | 147.58 | ||
Sheet2 |
i want like this
MMM.xlsm | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | Cus-Name | InVoice-No | First Bill-Amount | Second Bill-Amount | ||
2 | Raju.M | BVSI-001 | 1480.77 | 2339.53 | ||
3 | Swathi.P | BVSI-002 | 1480.77 | 1624.27 | ||
Sheet2 |
VBA Code:
Sub CombineRows()
Dim WorkRng As Range
Dim Dic As Variant
Dim arr As Variant
On Error Resume Next
xTitleId = "Excel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Set Dic = CreateObject("Scripting.Dictionary")
arr = WorkRng.Value
For i = 1 To UBound(arr, 1)
Dic(arr(i, 1)) = Dic(arr(i, 1)) + arr(i, 2)
Next
Application.ScreenUpdating = False
WorkRng.ClearContents
WorkRng.Range("A1").Resize(Dic.Count, 1) = Application.WorksheetFunction.Transpose(Dic.keys)
WorkRng.Range("B1").Resize(Dic.Count, 1) = Application.WorksheetFunction.Transpose(Dic.items)
Application.ScreenUpdating = True
End Sub