Create a summary list

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. Windows
Can anyone help me with a VBA code that will take this list and create a summary list in column W-Y. Each item should have a subtotal like in the example in the next table. The Ticker and Name are in column A & B and the Amounts are in column P. The output should be place in in C.

Greatly appreciate i anyone could offer your assistance. Thank you kindly.


Ticker NameAmount

<tbody>
</tbody>

BAThe Boeing Company $(617.90)
AAPLApple Inc. $(118.67)
AAPLApple Inc. $ 131.34
AAPLApple Inc.$(238.07)
BAThe Boeing Company $(374.06)
BAThe Boeing Company $(101.09)
BAThe Boeing Company $ 36.92
SPYSPDR S&P 500 ETF $ 304.10
AAPLApple Inc. $(538.29)
SPYSPDR S&P 500 ETF $ 274.10
SQSquare $ 466.71
AAPLApple Inc. $ 87.77
IBMInternational Business Machines Corporation $ 262.10
NVDANVIDIA Corporation $ 708.93
SPYSPDR S&P 500 ETF $ 286.69
BAThe Boeing Company $ 933.90

<tbody>
</tbody>



ickerNameTotal

<tbody>
</tbody>

AAPLApple Inc.$($657.92)
BAThe Boeing Company$(122.23)
IBMInternational Business Machines Corporation$262.10
NVDANVIDIA Corporation$708.93
SPYSPDR S&P 500 ETF$(864.89)
SQSquare$466.71

<tbody>
</tbody>
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
A little confusing you say create the Summary list in Cols "W:Y"
Then you say
The output should be place in in C.
 
Upvote 0
This if the data is not sorted !!

Code:
Sub MM1()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "a").End(xlUp).Row
Range("A2:B" & lr & ",P2:P" & lr).Copy Range("W2")
    Range("X2").Select
    ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("X1"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet2").Sort
        .SetRange Range("W2:Y" & lr)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
For r = lr To 2 Step -1
    If Cells(r, 24).Value = Cells(r - 1, 24).Value Then
        Cells(r - 1, 25).Value = Cells(r, 25).Value + Cells(r - 1, 25).Value
        Range(Cells(r, 23), Cells(r, 25)).Delete
    End If
Next r
End Sub
 
Last edited:
Upvote 0
I tried the code however, it does not take filter out unique names and total each unique name as in my example
 
Last edited:
Upvote 0
Hmm, works fine for me...is the sheet in question the activesheet ?
In the code the active sheet is "Sheet2", you may need to change that to suit whatever sheetname you are using

Code:
ActiveWorkbook.Worksheets([color=red]"Sheet2"[/color]).Sort.SortFields.Add Key:=Range("X1"), _
 
Upvote 0
I tried the code, but the math is not correct for the first row output. It shows 617.90, when it suppose to be 657.92. The rest looks like it achieves the task.
 
Last edited:
Upvote 0
Apple ince being the first compnay on the list, should be $-675.92, which agrees with col P AND col Y
Code:
Sub MM1()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
Range("A2:B" & lr & ",P2:P" & lr).Copy Range("W2")
    Range("X2").Select
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("X2"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.activesheet.Sort
        .SetRange Range("W2:Y" & lr)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
For r = lr To 2 Step -1
    If Cells(r, 24).Value = Cells(r - 1, 24).Value Then
        Cells(r - 1, 25).Value = Cells(r, 25).Value + Cells(r - 1, 25).Value
        Range(Cells(r, 23), Cells(r, 25)).Delete
    End If
Next r
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,570
Messages
6,120,297
Members
448,954
Latest member
EmmeEnne1979

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top