+ Reply to Thread
Results 1 to 8 of 8

Combine two rows and add values while remove one of the rows

Hybrid View

  1. #1
    Registered User
    Join Date
    03-24-2016
    Location
    US
    MS-Off Ver
    Pro Plus 2013
    Posts
    8

    Unhappy Combine two rows and add values while remove one of the rows

    Hello my name is Alex and I am a manager for a few cell phone stores and I need some help.
    So basically I have two separate rows in an excel file containing a rebate reimbursement for a single phone number but my POS is currently unable to match the two numbers and reimbursement amount together. This is what I'd like to do as easy as possible.

    -Match duplicates in a row (Phone numbers) Ex:Column A
    -add the two value together (Rebate Amount) Ex: Column C
    -Delete 2nd row after I get the sum

    Normally it wouldn't be an issue for me because I used to do this manually but they just promoted me to District Manager and now I have multiple store to take care of and doing it manually is really time consuming.

    In case I wasn't clear I attached an example. This is a very small version of what I am dealing with.


    Anyone that could help, would be doing me a great service.


    PS. File must remain in the same format, I don't think pivot table will actually assist

    Just for the sake clarification. I will update the Excel file to show what I have and what I'm trying to achieve.
    Attached Files Attached Files
    Last edited by sin2190; 03-24-2016 at 08:39 PM. Reason: Someone recommended pivot table.

  2. #2
    Valued Forum Contributor
    Join Date
    05-08-2015
    Location
    Uvalde, TX
    MS-Off Ver
    2010
    Posts
    720

    Re: Combine two rows and add values while remove one of the rows

    Hi,

    I recommend using a pivot table. It won't alter your data if you need it later.
    Also recommend caution when using "Format as Table". It appeared that you had your rows of data selected when you used "Format as Table". It made the file cumbersome to open.

    See attached file that has a pivot table of your data.


    Oh! and Congratulations on the job promotion.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    03-24-2016
    Location
    US
    MS-Off Ver
    Pro Plus 2013
    Posts
    8

    Re: Combine two rows and add values while remove one of the rows

    Alright so allow me to reiterate, the information on the excel file has to be adjusted.
    Basically this isn't for my information per-say but more for the POS system to be able to cross match this information with our expected reimbursements.
    So, for one, Col. A (Phone Numbers) can not have duplicates so one of the two rows have to be deleted.
    and two, the values(Col. C) of the rows with duplicates in Col A have to add up.

    Thank you for your attempt and also for the congrats.

  4. #4
    Registered User
    Join Date
    03-24-2016
    Location
    US
    MS-Off Ver
    Pro Plus 2013
    Posts
    8

    Re: Combine two rows and add values while remove one of the rows

    Feel free to view the updated excel file.

  5. #5
    Valued Forum Contributor
    Join Date
    05-08-2015
    Location
    Uvalde, TX
    MS-Off Ver
    2010
    Posts
    720

    Re: Combine two rows and add values while remove one of the rows

    How about this?

    I can't take credit for it. Borrowed it from Andrew Poulsom on: http://www.mrexcel.com/forum/excel-q...cate-rows.html
    Modified it to 3 columns.


    Sub Combine()
        Dim Sh As Worksheet
        Dim LastRow As Long
        Dim Rng As Range
        Set Sh = ActiveSheet
        Sh.Columns(4).Insert
        LastRow = Sh.Range("A65536").End(xlUp).Row
        With Sh.Range("A1:A" & LastRow).Offset(0, 3)
            .FormulaR1C1 = "=IF(COUNTIF(R1C[-3]:RC[-3],RC[-3])>1,"""",SUMIF(R1C[-3]:R[" & LastRow & "]C[-3],RC[-3],R1C[-1]:R[" & LastRow & "]C[-1]))"
            .Value = .Value
        End With
        Sh.Columns(3).Delete
        Sh.Rows(1).Insert
        Set Rng = Sh.Range("c1:c" & LastRow + 1)
        With Rng
            .AutoFilter Field:=1, Criteria1:="="
            .SpecialCells(xlCellTypeVisible).EntireRow.Delete
        End With
    End Sub
    The code is in the attached spreadsheet.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    03-24-2016
    Location
    US
    MS-Off Ver
    Pro Plus 2013
    Posts
    8

    Re: Combine two rows and add values while remove one of the rows

    OMG! I think thats it, but really quickly... Would you be able to adjusted the following
    17 Col.
    Phone Number is Col.7 or G Cell
    And Amount is Col. 15 or O Cell?
    So I can try it out.
    Please and thank you.

  7. #7
    Registered User
    Join Date
    03-24-2016
    Location
    US
    MS-Off Ver
    Pro Plus 2013
    Posts
    8

    Re: Combine two rows and add values while remove one of the rows

    Would you be able to please rewrite the code here but instead of inputting the Column letters can you put what they mean?
    I'd really appreciate learning a little more.

  8. #8
    Valued Forum Contributor
    Join Date
    05-08-2015
    Location
    Uvalde, TX
    MS-Off Ver
    2010
    Posts
    720

    Re: Combine two rows and add values while remove one of the rows

    I have modified it to work for Columns G and O. It is in the attached spreadsheet.

    As stated earlier I borrowed the original macro from Andrew Poulsom on: http://www.mrexcel.com/forum/excel-q...cate-rows.html

    When it come to excel and macro's I know enough to be dangerous. I don't know enough to even begin explaining how it works. Sorry

    Sub Combine()
        Dim Sh As Worksheet
        Dim LastRow As Long
        Dim Rng As Range
        Range("o1").Copy Range("p1")
            Set Sh = ActiveSheet
        Sh.Columns(16).Insert
        LastRow = Sh.Range("g65536").End(xlUp).Row
        With Sh.Range("g1:g" & LastRow).Offset(0, 9)
            .FormulaR1C1 = "=IF(COUNTIF(R1C[-9]:RC[-9],RC[-9])>1,"""",SUMIF(R1C[-9]:R[" & LastRow & "]C[-9],RC[-9],R1C[-1]:R[" & LastRow & "]C[-1]))"
            .Value = .Value
        End With
        Sh.Columns(15).Delete
        Sh.Rows(1).Insert
        Set Rng = Sh.Range("o1:o" & LastRow + 1)
        With Rng
            .AutoFilter Field:=1, Criteria1:="="
            .SpecialCells(xlCellTypeVisible).EntireRow.Delete
        End With
        Range("p1").Cut Range("o1")
    End Sub
    Attached Files Attached Files

+ 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] Combine values multiple rows
    By spiklz in forum Excel General
    Replies: 5
    Last Post: 09-06-2015, 09:13 PM
  2. Combine rows with duplicate values into separate columns
    By itgeekgroup in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-18-2014, 11:12 AM
  3. Combine Duplicate Rows and Combine Data in Rows
    By cherylmcgk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2013, 12:04 PM
  4. Combine rows with similar values in one column.
    By sgtpepper in forum Excel General
    Replies: 1
    Last Post: 12-06-2011, 09:31 PM
  5. Combine rows with similar values in one column.
    By sgtpepper in forum Excel General
    Replies: 3
    Last Post: 12-06-2011, 01:43 PM
  6. Remove row duplicates depending on values from other rows
    By soli004 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-22-2011, 06:09 PM
  7. Replies: 4
    Last Post: 12-04-2007, 03:08 PM

Tags for this Thread

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