+ Reply to Thread
Results 1 to 3 of 3

Eliminating common names while creating one name with summed values

Hybrid View

nocty Eliminating common names... 02-24-2010, 03:05 PM
Leith Ross Re: Eliminating common names... 02-24-2010, 07:32 PM
DonkeyOte Re: Eliminating common names... 02-25-2010, 04:53 AM
  1. #1
    Registered User
    Join Date
    02-24-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2003
    Posts
    1

    Eliminating common names while creating one name with summed values

    Hello, I am building an excel spreadsheet that basically has the same problem name with different values through out the month. For example

    Hotdogs - 25
    Hotdogs - 30
    Hotdogs - 20
    Hotdogs - 15
    Pizza - 10
    Pizza - 15
    Pizza - 20
    Pizza - 5
    Soda - 10
    Soda - 15
    Soda - 20
    Soda - 15

    I would like to Sum the values and create one unique record for my reports such as
    Hotdogs - 90
    Pizza - 50
    Soda - 60

    I have figured out how to use the Sumif function but I do not know how to create one record with the sum totals. Any help would be much appreciated.

    Thank you for your help.
    Last edited by nocty; 02-24-2010 at 03:50 PM. Reason: Forum Rules

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Eliminating common names while creating one name with summed values

    Hello nocty,

    The attached workbook has 2 sheets: List and Report. The List contains the example data you posted. The Report sheet contains the names and the counts. This macro could be adapted to your workbook. However, without seeing your workbook I can't make any needed adjustments. The macro below has been added to a button on the List sheet.
    Sub CreateReport()
    
      Dim Cell As Range
      Dim DSO As Object
      Dim Item As Variant
      Dim Key As String
      Dim ListWks As Worksheet
      Dim ReportWks As Worksheet
      Dim Rng As Range
      Dim RngEnd As Range
      
        Set ListWks = Worksheets("List")
        Set ReportWks = Worksheets("Report")
        
        Set Rng = ListWks.Range("A2:B2")
        Set RngEnd = ListWks.Cells(Rows.Count, Rng.Column).End(xlUp)
        Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, ListWks.Range(Rng, RngEnd))
        
        Set DSO = CreateObject("Scripting.Dictionary")
        DSO.CompareMode = vbTextCompare
        
          ReportWks.UsedRange.Offset(1, 0).ClearContents
          
          For Each Cell In Rng.Columns(1).Cells
            Key = Trim(Cell)
            Item = Cell.Offset(0, 1).Value
            If Not DSO.Exists(Key) Then
               DSO.Add Key, Item
            Else
               DSO(Key) = DSO(Key) + Item
            End If
          Next Cell
          
        ReportWks.Cells(2, "A").Resize(DSO.Count, 1) = WorksheetFunction.Transpose(DSO.Keys)
        ReportWks.Cells(2, "B").Resize(DSO.Count, 1) = WorksheetFunction.Transpose(DSO.Items)
      
        Set DSO = Nothing
        
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Eliminating common names while creating one name with summed values

    Or alternatively use a Pivot Table - for general intro see link in sig.

    Pivots are purpose built for this type of aggregation work.

    IMO - Pivots should be the first thing any XL user gets to grip with as they can literally hours of work - they require no formula knowledge per se and offer immense reporting power & flexibility for no effort.
    (they also illustrate why it's a good idea to store "transactional" data in a tabular manner as you have done)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1