+ Reply to Thread
Results 1 to 5 of 5

Concatenate without duplicates in descending order according to the sum

Hybrid View

Petros Georgilas Concatenate without... 12-08-2014, 09:32 AM
Kaper Re: Concatenate without... 12-08-2014, 11:15 AM
Petros Georgilas Re: Concatenate without... 12-08-2014, 02:28 PM
Kaper Re: Concatenate without... 12-11-2014, 07:04 AM
Petros Georgilas Re: Concatenate without... 12-11-2014, 10:21 AM
  1. #1
    Registered User
    Join Date
    03-13-2013
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    30

    Concatenate without duplicates in descending order according to the sum

    concatenate sort sum descending.xlsx
    Hello,
    please see attached file
    In range c3:c10 we have: USA, Canada, China, USA, France, Greece, Turkey, Canada

    In range h5:h12 (the point is that the two ranges may not be next to each other and/or at the same horizontal level. They will have the same number of cells though) we have 6, 3, 10, 8, 0, , 0, 2

    I am looking for a way, preferably a User Defined Formula where I would have to define the two ranges, to concatenate the countries in descending order based on the sums of their respective value. In addition, it should exclude countries where the sum of their values is 0.
    So in our example the formula should return "USA, China, Canada"
    Some comments
    1) The values may not be integers
    2) The values may not be positive numbers
    3) China has the largest single value (10) but it comes second to USA because the sum for USA is 6+8=14 which is larger than 10

    If it is any help, you may get some ideas from the thread under the name "Concatenate if other column value is non-blank or non-zero BUT IN DESCENDING ORDER"

    Thanks a lot!
    Last edited by Petros Georgilas; 12-08-2014 at 02:16 PM. Reason: included attachment

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Concatenate without duplicates in descending order according to the sum

    No attachment, so I'll not waste my time to prepare sample sheet for you. (see http://www.excelforum.com/forum-rule...rum-rules.html - section "Want to get your question answered quickly?")

    Easy way to get it done properly would be to copy both ranges, give them headers, and then do a pivot table - sorting and filtering result would be a snap.

    Yes, it can be done also with formulas, but do not expect especially short version here.
    Also doing it without helper cells/column not necesserily would be that easy.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    03-13-2013
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    30

    Re: Concatenate without duplicates in descending order according to the sum

    You are right Kaper. Sorry!
    I uploaded the attachment.
    This is just an example. In the actual file, I will perform this action multiple times and probably with values that will change from time to time. So copying the ranges and creating pivot tables every time does not really work. The ideal would be a User Defined Function (i.e. a function created using VBA). I was thinking sth like the solution in the thread under the name "Concatenate if other column value is non-blank or non-zero BUT IN DESCENDING ORDER".
    I can create a new sheet where each country will be shown just once and calculate the values using "sumif" and then use the UDF in the thread I mentioned. However, new countries may be added in the future and more importantly the excel is for a friend not very familiar with excel, so I am looking for something more elegant.
    Thanks

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Concatenate without duplicates in descending order according to the sum

    Hi Petros,
    You can use the function proposed there (in prevoius thread), but add a stage of collating entries first.
    For instance, based on xladept approcach, but adding provisions for non-integer and for negative values:
    Function CCHiLoX(R As Range, S As Range) As String
    Dim P As String, P2 As Double, Q, T, i As Long, earlier As Long
    Q = R
    T = S
    If Not IsNumeric(R(1, 1)) Then Q(1, 1) = 0
    With Application.WorksheetFunction
      For i = 2 To S.Rows.Count
        If IsNumeric(R(i, 1)) Then
          If .CountIf(S.Resize(i - 1, 1), S(i, 1)) > 0 Then
            earlier = .Match(S(i, 1), S.Resize(i - 1, 1), 0)
            Q(earlier, 1) = Q(earlier, 1) + Q(i, 1)
            Q(i, 1) = 0
          End If
        Else
          Q(i, 1) = 0
        End If
      Next i
    End With
    BubbleQ:
    For i = LBound(Q) To UBound(Q) - 1
      If Q(i, 1) < Q(i + 1, 1) Then
        P2 = Q(i, 1)
        Q(i, 1) = Q(i + 1, 1)
        Q(i + 1, 1) = P2
        P = T(i, 1)
        T(i, 1) = T(i + 1, 1)
        T(i + 1, 1) = P
        GoTo BubbleQ
      End If
    Next i
    For i = LBound(Q) To UBound(Q)
      If Q(i, 1) <> 0 Then
        CCHiLoX = CCHiLoX & "," & T(i, 1)
      End If
    Next i
    CCHiLoX = Right(CCHiLoX, Len(CCHiLoX) - 1)
    End Function
    PS. Looks much longer, but it's not - Is written here without collapsing several instructions into 1 row with : separator.

  5. #5
    Registered User
    Join Date
    03-13-2013
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    30

    Re: Concatenate without duplicates in descending order according to the sum

    Thanks a lot Kaper!
    It seems to be just what i needed!
    I will study in due time and try to understand

+ 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] Concatenate if other column value is non-blank or non-zero BUT IN DESCENDING ORDER
    By Petros Georgilas in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 12-08-2014, 04:26 PM
  2. [SOLVED] Rank values in descending order with duplicates
    By mcain1981 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-14-2012, 01:15 PM
  3. Excel 2007 : Extract by descending order
    By Shilpa kanchan in forum Excel General
    Replies: 1
    Last Post: 12-25-2011, 03:53 AM
  4. vlookup in descending order
    By thebigmancometh in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-01-2010, 09:41 AM
  5. vlookup in descending order
    By thebigmancometh in forum Excel General
    Replies: 1
    Last Post: 02-16-2010, 06:13 AM

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