+ Reply to Thread
Results 1 to 5 of 5

Array to put results in one column in to one cell

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-24-2012
    Location
    Australia
    MS-Off Ver
    Office365
    Posts
    309

    Array to put results in one column in to one cell

    Hi Experts,
    Would appreciate any suggestion for array to put 1 to 4 cells (max) results from one column in to one cell.

    TOTAL No. Rank
    10 1 4
    20 1
    30 1 2
    40 1 1

    Last column results to put in one cell as 4,2,1, or 421

    Attached sheet may assist clearly
    Thanks in advance
    Karnik
    Attached Files Attached Files

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Array to put results in one column in to one cell

    This formula

    =concatall(IF($C$3:$C$22=G2,IF($D$3:$D$22<>"",$D$3:$D$22,""),""),"")

    array entered, along with this code in a module:

    Public Function ConcatAll(ByVal varData As Variant, Optional ByVal sDelimiter As String = vbNullString, Optional ByVal bUnique As Boolean = False) As String
       
        Dim DataIndex As Variant
        Dim strResult As String
        
        If IsArray(varData) _
        Or TypeOf varData Is Range _
        Or TypeOf varData Is Collection Then
            
            For Each DataIndex In varData
                If Len(DataIndex) > 0 Then
                     If bUnique = True Then
                          If InStr(1, "||" & strResult & "||", "||" & DataIndex & "||", vbTextCompare) = 0 Then
                           trResult = strResult & "||" & DataIndex
                        End If
                    Else
                        strResult = strResult & "||" & DataIndex
                    End If
                End If
            Next DataIndex
            
            strResult = Replace(Mid(strResult, 3), "||", sDelimiter)
            
        Else
            strResult = varData
        End If
        
        ConcatAll = strResult
        
    End Function
    does that.


    Array Formulae are a little different from ordinary formulae in that they MUST be confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER.

    You will know the array is active when you see curly brackets { } - or "curly braces" for those of you in the USA, or "flower brackets" for those of you in India - appear around the outside of your formula. If you do not use CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.

    Don't type the curly brackets yourself - it won't work...

    Remember to enable macros on opening...
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Array to put results in one column in to one cell

    Nope. forget all that. use this array formula instead: No need for VBA. It gives the results concatenated and in ascending order.

    =CONCATENATE(IFERROR(SMALL(IF(($C$3:$C$22=G2)*($D$3:$D$22> 0),$D$3:$D$22),1),""),IFERROR(SMALL(IF(($C$3:$C$22=G2)*($D$3:$D$22> 0),$D$3:$D$22),2),""),IFERROR(SMALL(IF(($C$3:$C$22=G2)*($D$3:$D$22> 0),$D$3:$D$22),3),""),IFERROR(SMALL(IF(($C$3:$C$22=G2)*($D$3:$D$22> 0),$D$3:$D$22),4),""),"")
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    06-24-2012
    Location
    Australia
    MS-Off Ver
    Office365
    Posts
    309

    Re: Array to put results in one column in to one cell

    Hi Glen,
    Thanks for Solution, complex issue is made very simple
    Thanks
    Karnik

  5. #5
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Array to put results in one column in to one cell

    You're welcome and thanks 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] how can i make this array change the cell in a column based on a text array
    By dmcgov in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-25-2016, 09:44 AM
  2. [SOLVED] Find cell in 2nd array using row and column from the first array Excel 2010 VBA
    By crywolf in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-08-2015, 02:12 PM
  3. Replies: 13
    Last Post: 06-18-2014, 08:14 PM
  4. [SOLVED] Index/Match Array with multiple results concatenate in one cell
    By samiesosa in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-15-2013, 01:34 PM
  5. Replies: 6
    Last Post: 05-26-2012, 04:56 AM
  6. Lookup data in array, results in column 1
    By dslomski in forum Excel General
    Replies: 3
    Last Post: 02-23-2009, 10:49 AM
  7. [SOLVED] Wanting to write results to array instead of sheet, results overwriting....
    By sarjuhindocha@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2005, 10:05 AM

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