+ Reply to Thread
Results 1 to 8 of 8

Combine specific line items on invoice

Hybrid View

  1. #1
    Registered User
    Join Date
    08-16-2016
    Location
    Illinois, USA
    MS-Off Ver
    Office 365
    Posts
    49

    Combine specific line items on invoice

    I am needing a macro to combine/sum two line items when they exist together on an invoice. They do not exist on every invoice, and they do not always exist together on an invoice. I've attached an example of the raw data that I am working with. Invoice numbers are in column A, item numbers in column F, amounts per item in column L. The two item numbers are UN0000075 AND UN0000083. Item number ending 83 will never exist without 75, but 75 can exist without 83. Ideally I would like for the items to be summed onto the row containing item number ending 75, and then the row with item 83 removed completely, and the item description changed to Tax.

    Thank you in advance for any help you can provide.
    Attached Files Attached Files

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,855

    Re: Combine specific line items on invoice

    I'm not sure if I understood correctly but try this macro on a copy of your workbook.
    Sub SumItems()
        Application.ScreenUpdating = False
        Dim LastRow As Long, InNum As Range, Count83 As Range, Count75 As Range
        LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        Sheets("Sheet1").Range("A1:A" & LastRow).AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("A1:A" & LastRow), Unique:=True
        Set rnguniques = Sheets("Sheet1").Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible)
        For Each InNum In rnguniques
            Range("A1:R" & LastRow).AutoFilter Field:=1, Criteria1:=InNum
            Set Count75 = Range("F2:F" & LastRow).SpecialCells(xlCellTypeVisible).Find("UN0000075")
            Set Count83 = Range("F2:F" & LastRow).SpecialCells(xlCellTypeVisible).Find("UN0000083")
            If Not Count75 Is Nothing And Not Count83 Is Nothing Then
                Range("L" & Count75.Row) = WorksheetFunction.Sum(Range("L" & Count75.Row) + Range("L" & Count83.Row))
                Rows(Count83.Row).EntireRow.Delete
            End If
        Next InNum
        Range("A1").AutoFilter
        Application.ScreenUpdating = True
    End Sub
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    08-16-2016
    Location
    Illinois, USA
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Combine specific line items on invoice

    Thank you for the quick response! It appears to work on a very small selection of data, but when applied to a larger data set I still see several that were missed. I've uploaded a 2nd example copy with a larger dataset.

    Thanks again for your help.
    Attached Files Attached Files

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,855

    Re: Combine specific line items on invoice

    Could you please attach another copy of your file highlighting the data/rows that were missed with a color so that they are easy to see?

  5. #5
    Registered User
    Join Date
    08-16-2016
    Location
    Illinois, USA
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Combine specific line items on invoice

    Updated example attached.

    Thank you.
    Attached Files Attached Files

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,855

    Re: Combine specific line items on invoice

    Try:
    Sub SumItems()
        Application.ScreenUpdating = False
        Dim LastRow As Long, InNum As Range, Count83 As Range, Count75 As Range, rng As Range
        LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        Dim RngList As Object, Key As Variant
        Set RngList = CreateObject("Scripting.Dictionary")
        For Each InNum In Sheets("Sheet1").Range("A2:A" & LastRow)
            If Not RngList.Exists(InNum.Value) Then
                RngList.Add InNum.Value, Nothing
            End If
        Next InNum
        For Each Key In RngList.keys
            Range("A1:R" & LastRow).AutoFilter Field:=1, Criteria1:=Key
            Set Count75 = Range("F2:F" & LastRow).SpecialCells(xlCellTypeVisible).Find("UN0000075")
            Set Count83 = Range("F2:F" & LastRow).SpecialCells(xlCellTypeVisible).Find("UN0000083")
            If Not Count75 Is Nothing And Not Count83 Is Nothing Then
                Range("L" & Count75.Row) = WorksheetFunction.Sum(Range("L" & Count75.Row) + Range("L" & Count83.Row))
                Rows(Count83.Row).EntireRow.Delete
            End If
            Range("A1").AutoFilter
        Next Key
        Application.ScreenUpdating = True
    End Sub

  7. #7
    Registered User
    Join Date
    08-16-2016
    Location
    Illinois, USA
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Combine specific line items on invoice

    Thank you again for the reply. This works wonderfully! Marking the thread as solved and +rep.

    Have a great day!

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,855

    Re: Combine specific line items on invoice

    You are very welcome and thank you for the rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Split invoice file in max 1000 line items
    By Crispy85 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 08-11-2015, 02:39 AM
  2. Invoice Sales Tracker is messing up the invoice items
    By Kristina86 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-05-2015, 06:47 AM
  3. Combine Line Items From Columns/List
    By BrewsterBruiser in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-31-2014, 10:17 AM
  4. Replies: 1
    Last Post: 06-12-2014, 10:58 AM
  5. [SOLVED] Combine like invoice items into total amount
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-05-2013, 11:19 PM
  6. Re: Invoice with many items?
    By MikeHunt in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-09-2010, 04:46 AM
  7. How do I combine quantities of similar line items
    By Joshua Hullender in forum Excel General
    Replies: 2
    Last Post: 01-03-2006, 07:45 PM

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