+ Reply to Thread
Results 1 to 13 of 13

Looking for a single text value and returning 1 or multiple text values in one cell

Hybrid View

  1. #1
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Looking for a single text value and returning 1 or multiple text values in one cell

    This should do it

    Sub abc()
     Dim i As Long, ii As Long, a
     
     With Worksheets("sheet1")
        a = .Range("a1").CurrentRegion
     End With
     
     With CreateObject("scripting.dictionary")
        .comparemode = 1
        For i = 1 To UBound(a)
            If Not IsEmpty(a(i, 1)) Then
                ii = i
                .Item(a(i, 1)) = a(i, 3)
            Else
                .Item(a(ii, 1)) = .Item(a(ii, 1)) & ", " & a(i, 3)
            End If
        Next
        With Worksheets("sheet2")
            a = .Range("a2", .Cells(Rows.Count, 1).End(xlUp).Offset(, 1))
        End With
        For i = 1 To UBound(a)
            If .exists(a(i, 1)) Then a(i, 2) = .Item(a(i, 1))
        Next
        With Worksheets("sheet2")
            .Range("a2").Resize(UBound(a), UBound(a, 2)) = a
        End With
     End With
    End Sub
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  2. #2
    Registered User
    Join Date
    10-22-2014
    Location
    Amsterdam
    MS-Off Ver
    2010
    Posts
    21

    Re: Looking for a single text value and returning 1 or multiple text values in one cell

    Hi Mike,
    Thank you very much for your fantastic macro! It works perfectly in the demo file. However, when I use your macro (somewhat adapted) in my real file, I get the error message: "subscript out of range".
    Sheet1 in my original file is a PivotTable, is this a big problem? Hope not.
    Additionally, the first text in sheet1 starts in cell A7. Therefor I adjusted your code (line 5) "a1" to "a7". This works in the demo file so I assume this is correct. I also adjusted the sheet names but I don’t know if it’s possible that sheet names contain spaces?
    Sheet2 starts at cell A3. Is it necessary to make a code adjustment for that?
    Finally, I'd like the result in another column (not B but M). Do not know how to modify the code for that.

    Hopefully you can to help me with the final adjustments. Already many thanks in advance!
    With kind regards,
    Marc

+ 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. Looking for a single text value and returning 1 or multiple text values
    By cramnij in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-22-2014, 08:37 PM
  2. Replies: 2
    Last Post: 04-30-2014, 05:59 AM
  3. [SOLVED] Excel - Returning multiple values in a single cell that match criteria
    By amazinz2006 in forum Excel General
    Replies: 13
    Last Post: 01-25-2014, 09:35 PM
  4. Returning a value to a single cell based on multiple values elsewhere.
    By archieross in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-05-2012, 07:35 PM
  5. Replies: 3
    Last Post: 08-02-2010, 10:07 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