+ 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

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

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

    Hello,
    As suggested by Azumi this problem can probably be solved by a macro or a VBA code. Hope someone can help me with my following problem.
    I want to lookup a certain text value from a worksheet (sheet 2 in example file) and find this exact text value in worksheet 1 column A. Then the result must be the corresponding text value (or values!!) from sheet 1 column C. I want the result in a single cell next to the lookup value (sheet 2).

    See attached file DemoMarc3.
    For example: if I lookup "Hello" the result must be: "Amsterdam". But when I Lookup "Hay" the result must be: "New York, Berlin". And when I lookup "Good Morning" the result must be: "Madrid, Madras, Amsterdam, New York". The number of empty cells between the text that I want to find in column A and the next text in column A is not a constant and will vary.
    Thanks so much for all your help.
    Marc
    Attached Files Attached Files

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

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

    This should do it

    Please Login or Register  to view this content.
    Thanks,
    Mike

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

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

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

    Maybe:

    Please Login or Register  to view this content.

  4. #4
    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

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

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

    Can you upload a more realaistic workbook of how your data is laid out?

  6. #6
    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

    Hey Mike,
    As you asked, I’ve tried to make a more realistic workbook of my data. But the problem does not occur in that file. So I found that extracting data from a pivot table is not the problem. I think it’s my original pivot table that causes the problem. But why and where I can’t figure out. Here is a photo of the code and the error line a(ii,1)=<subscript out of range>. Maybe it can help you to figure out what’s wrong.

    code with error line subscript out of range.JPG

    Due to upload limitations it’s not possible to upload my original file (to big).
    Now I found a workaround for the still existing problem in my original file, the only thing I can’t workout is how to put the data in a different column (not B but M).
    Hopefully you can help me with that last hurdle.
    Thanks.
    Marc
    Last edited by cramnij; 11-05-2014 at 06:02 AM.

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

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

    Something like this, If that dont work cut down your file and see if it will upload

    Please Login or Register  to view this content.

  8. #8
    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,
    Almost perfect! Data ends up in the right column.
    But its starts with the lookup data in column M and the result data in the next column (N).
    Is it possible to put only the result data in column M? I don't need the lookup data to be returned also.
    Thanks.
    Marc

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

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

    Try this

    Please Login or Register  to view this content.

  10. #10
    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,
    That did the trick! But…. Sorry to be such a pain…. when the lookup data is not found it will return the lookup data as a result. Is it possible to return a blank cell when the lookup is not to be found? Thanks a million!
    Marc

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

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

    Please Login or Register  to view this content.
    Last edited by mike7952; 11-06-2014 at 07:22 AM.

  12. #12
    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,
    It's perfect! Your the Best!! Thanks a million!!!
    Marc

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

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

    Your welcome

+ 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