+ Reply to Thread
Results 1 to 11 of 11

Use Macro to Sum Dupes then delete - Help please

  1. #1
    Registered User
    Join Date
    02-05-2011
    Location
    LA, CA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Question Use Macro to Sum Dupes then delete - Help please

    I am trying to use a macro to sum all duplicates, then delete all but one. I have data in column A that is duplicated, totals in column B that I would like summed. I can add al into B or sum in C, I would then like all of the dupes to be deleted (except one with the sum, of course). I tried Pivot Tables and couldn't make them work.


    Column A Column B Column C
    Invoice Gross Amt Gross amt no Dupes
    1234 100.00
    1234 -50.00
    1245 200.00
    1245 -50.00
    1234 25.00

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Use Macro to Sum Dupes then delete - Help please

    Hi annasproule and welcome to the forum,

    I'd try pivot tables again. It will sum and only show a single Invoice Number. Leave the dupes. See the attached.

    Also read http://office.microsoft.com/en-us/ex...001034626.aspx for dupes in 2003 but it got a lot easier with 2007. http://www.lytebyte.com/2008/06/10/h...es-excel-2007/
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    02-05-2011
    Location
    LA, CA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Use Macro to Sum Dupes then delete - Help please

    The total number of columns and rows exceed what it will let me pull in for the pivot table. I have over 20K rows and 25 columns. I am not really very good at this stuff, but my programmer is out for 2 weeks, so I am trying to relearn from like 10 years ago

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Use Macro to Sum Dupes then delete - Help please

    Hi Annasproule,

    You said "exceeds what it well let me pull into a pivot table". That surprised me as doing a pivot table is a lot easier than writing VBA code. Read http://support.microsoft.com/kb/820742 and this was for 2000 excel.

    Do you get an error message? Can we help with the "exceeds" problem?

    If you could do a single pivot table and then copy and paste it to "Values Only" you would get your answer without needing any code.

    If Pivot Tables won't do it for you, how about an Advanced Filter to get unique Invoice numbers. Then do a SumIf formula to add all amounts tied to that invoice number. Might this work for you? See http://www.contextures.com/xladvfilter01.html for this topic.

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

    Re: Use Macro to Sum Dupes then delete - Help please

    Hello annasproule,

    Since you said you have 25 columns, I am guessing there is one column for the invoice number and 24 more for each month spanning 2 years. If your worksheet layout is the same as the layout of the attached example then you can copy the macro into your workbook. You made need to change the worksheet names in macro. These are in marked in bold below.

    The Grand totals are listed on a separate sheet. This allows you have a backup of the original data.
    Please Login or Register  to view this content.
    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!)

  6. #6
    Registered User
    Join Date
    02-05-2011
    Location
    LA, CA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Use Macro to Sum Dupes then delete - Help please

    Marvin,
    It give me an error message when I pull over all of the Columns. I need the data from all of the columns. The error message says that the number of columns exceed 250

  7. #7
    Registered User
    Join Date
    02-05-2011
    Location
    LA, CA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Use Macro to Sum Dupes then delete - Help please

    Leith,

    The columns have other pertinent data. I have attached a more lengthy example below. The data that has duplicates is in column A. The data I need summed is in column Q. I cannot get anything to work I have additional columns after Q also, but they are confidential, so I cannot post.
    Attached Files Attached Files

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

    Re: Use Macro to Sum Dupes then delete - Help please

    Hello annasproule,

    Easy fix. The correction is in bold below. The attached workbook has the macro and a button to run it added on "Sheet2".
    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Use Macro to Sum Dupes then delete - Help please

    Hi,

    I'm guessing it was with earlier versions of Excel that this limit was reached.
    Is there a chance you could limit the columns of the Pivot table to include less? If you made your column range from columns A to Q as in your sample it might work fine. See the attached to see.
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Use Macro to Sum Dupes then delete - Help please

    see attachment, save the attached file and make sure the following reference is on:

    1. [Alt+F11] - open Visual Basic window
    2. Tools - References - find and tick "Microsoft Activex Data Objects 2.0 Library"
    3. Run macro "Test"
    Attached Files Attached Files
    Last edited by watersev; 02-06-2011 at 06:33 PM.

  11. #11
    Registered User
    Join Date
    02-05-2011
    Location
    LA, CA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Use Macro to Sum Dupes then delete - Help please

    Leith,

    Thank you SOOOOOO much!! That worked perfectly!!

    I now have a different predicament. Maybe I should have posted a longer question. LOL

    So now I have all of the data summed, but it left out all of the other info. I will post a new thread since it is a somewhat different issue.
    Thank you very much for your patience!!

+ 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