+ Reply to Thread
Results 1 to 8 of 8

VBA Excel 2010 - Dictionary with Array Suppress duplicates plus sum amount column

  1. #1
    Registered User
    Join Date
    06-20-2014
    Location
    France
    MS-Off Ver
    2010
    Posts
    8

    VBA Excel 2010 - Dictionary with Array Suppress duplicates plus sum amount column

    Hello

    I have a Excel sheet containing a key (column A) and some columns (fixed value or amount).

    I want the macro to suppress duplicates (keys) and at the same time sum amount for duplicates

    Ex.
    CCSA07194EUR M03/2014 EUR I 201403 CCSA07 -1033985
    CCSA07220EUR M03/2014 EUR I 201403 CCSA07 -37840,17
    CCSA07220EUR M03/2014 EUR I 201403 CCSA07 -37840,17
    CCSA07220EUR M03/2014 EUR I 201403 CCSA07 -37840,17

    expected results
    CCSA07194EUR M03/2014 EUR I 201403 CCSA07 -1033985
    CCSA07220EUR M03/2014 EUR I 201403 CCSA07 -113520,51 (sum of : -37840,17 x 3)


    Due to number of lines (30.000), I tried to use the dictionary with function in Excel.

    I created 2 dictionaries (one containing fixed values), another one for amount.

    When transposing the value, column A gets the key (ok) but error message therefore I don't have any values for column B/C the values and column D not the sumed amounts

    Attached the Excel file (not the 30.000 lines, just a test case with a couple of lines) including the macro.
    Thanks in advance for any idea how to solve this.
    Attached Files Attached Files

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

    Re: VBA Excel 2010 - Dictionary with Array Suppress duplicates plus sum amount column

    hi ffasan, option, run code "test"
    Attached Files Attached Files
    Last edited by watersev; 07-25-2014 at 04:07 AM.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA Excel 2010 - Dictionary with Array Suppress duplicates plus sum amount column

    Try this

    Change 15 to # of columns that you want it to the result.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-20-2014
    Location
    France
    MS-Off Ver
    2010
    Posts
    8

    Re: VBA Excel 2010 - Dictionary with Array Suppress duplicates plus sum amount column

    THanks to both of you. I finally found out with dictionary w/o looping:

    Sub doublons()
    Set d1 = CreateObject("Scripting.Dictionary")
    Set d2 = CreateObject("Scripting.Dictionary")
    Dim i As Long

    For Each c In Range("A1:A16")
    d1(c.Value) = Array(c.Offset(, 1), c.Offset(, 2))
    d2(c.Value) = d2(c.Value) + c.Offset(, 7)
    Next c
    [a20].Resize(d1.Count, 1) = Application.Transpose(d1.keys)
    [b20].Resize(d1.Count, 1) = Application.Transpose(Application.Index(d1.items, 1, 1)) 'would like to take the 1st value of Array c.offset(,1)
    [c20].Resize(d1.Count, 1) = Application.Transpose(Application.Index(d1.items, 1, 2)) 'would like to take the 2nd value of Array c.offset(,2)
    [d20].Resize(d2.Count, 1) = Application.Transpose(d2.items)
    End Sub

  5. #5
    Registered User
    Join Date
    06-20-2014
    Location
    France
    MS-Off Ver
    2010
    Posts
    8

    Re: VBA Excel 2010 - Dictionary with Array Suppress duplicates plus sum amount column

    Strangely the code is working is my test workbook but when I try to replicate the code in the production workbook,
    I received a message error 13 (type incompatibility)
    ... any idea why ?(I have attached the solution that is working out just fine).
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA Excel 2010 - Dictionary with Array Suppress duplicates plus sum amount column

    Quote Originally Posted by ffasan View Post
    THanks to both of you. I finally found out with dictionary w/o looping:
    Please Login or Register  to view this content.
    W/O loop?

    What is your definition about "Loop"?

  7. #7
    Registered User
    Join Date
    06-20-2014
    Location
    France
    MS-Off Ver
    2010
    Posts
    8

    Re: VBA Excel 2010 - Dictionary with Array Suppress duplicates plus sum amount column

    Loop or For/Next. I was looking for avoiding one of the two when writing the results (not selecting).

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA Excel 2010 - Dictionary with Array Suppress duplicates plus sum amount column

    Let us know if you find the way to solve it w/o loop.

    Good luck.

+ 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. help assigning elements of dictionary to array and then pasting array into worksheet
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-05-2013, 10:37 AM
  2. 2010 VBA - Ordered by Collection or Scripting.Dictionary
    By Herve_Rob in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-06-2013, 12:14 PM
  3. Replies: 12
    Last Post: 02-01-2013, 04:53 PM
  4. Replies: 2
    Last Post: 12-02-2011, 03:42 PM
  5. [SOLVED] Suppress array formula #NA
    By [email protected] in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-15-2005, 01:20 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