+ Reply to Thread
Results 1 to 2 of 2

Grouping Part Numbers

Hybrid View

  1. #1
    Registered User
    Join Date
    08-29-2011
    Location
    Cedar Rapids, IA
    MS-Off Ver
    Excel 2010
    Posts
    1

    Grouping Part Numbers

    Hi, I have a program that exports all part numbers for a project, along with quantities, into excel. This program is basic, and if I have one part number called out 6 times, with 6 different quantities (or the same) it will put it into the spreadsheet 6 different times. Is there a way to sort, then combine each part number, so I only see each part number once, with the total quantity? I have a bit of programming experience, but none with excel, so if someone can just get me started in the right direction it would be much appreciated.

    Thanks,
    Alan

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Grouping Part Numbers

    ItsAlan,

    If the data has headers, part numbers are in column A, and Quantity in column B, you should be able to use the following macro:
    Sub tgr()
        
        Static rngPrts As Range: Set rngPrts = Intersect(ActiveSheet.UsedRange, ActiveSheet.Columns("A"))
        Static rngDest As Range: Set rngDest = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Offset(1, 4)
        Application.ScreenUpdating = False
        
        rngPrts.AdvancedFilter xlFilterCopy, rngPrts, rngDest, True
        Dim arrPrts As Variant: arrPrts = Range(rngDest.Offset(1), rngDest.End(xlDown)).Resize(, 2).Value
        rngDest.EntireColumn.Delete
        
        Dim PrtIndex As Long
        For PrtIndex = 1 To UBound(arrPrts, 1)
            arrPrts(PrtIndex, 2) = WorksheetFunction.SumIf(rngPrts, arrPrts(PrtIndex, 1), rngPrts.Offset(, 1))
        Next PrtIndex
        
        rngPrts.Offset(1).Resize(, 2).ClearContents
        Range("A2").Resize(UBound(arrPrts, 1), 2).Value = arrPrts
        
    End Sub


    Hope that helps,
    ~tigeravatar

+ 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