+ Reply to Thread
Results 1 to 6 of 6

look for value in cells in a row, return multiple column names

  1. #1
    Registered User
    Join Date
    10-27-2012
    Location
    londan, england
    MS-Off Ver
    Excel 2007
    Posts
    3

    look for value in cells in a row, return multiple column names

    i have a table from a supplier, that has states listed in the column name, then a Y (for yes) in each corresponding column for restricted shipping to that state. so for instance, there is a product that has restricted shipping to DC, IL, and MA, each have a "Y" in the cell in that column for the product, then blanks in the rest. i want to return all of those column names (states) into one cell for importing into my store for the products description. is there a way to do that? i've had halfway success using the lookup and index functions, but they only return one value. i need it to return all column names where the "Y" is. can anyone help?

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: look for value in cells in a row, return multiple column names

    Try this user defined function.

    Please Login or Register  to view this content.
    Open the VBA editor by hitting Alt F11.
    Insert a new module with Insert - Module
    Paste in the above function
    Go back to the sheet by hitting Alt F11.

    In a suitable cell, enter = =GetStates($B$1:$L$1,B2:L2) or similar and copy down.

    Remember to save the workbook as a macro enabled workbook .xlsm
    Martin

  3. #3
    Forum Contributor dogberry's Avatar
    Join Date
    07-15-2012
    Location
    Wales, UK
    MS-Off Ver
    Excel 2010
    Posts
    624

    Re: look for value in cells in a row, return multiple column names

    Hi

    Can you post a dummy sample spreadsheet so we can see the layout and what you are trying to do.

    Thanks

    Chris
    Click my star if I helped Thanks

  4. #4
    Registered User
    Join Date
    10-27-2012
    Location
    londan, england
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: look for value in cells in a row, return multiple column names

    this is basically what i would need in the restricted shipping field, but a formula to do it for me as i have around 11k products and various states with restricted shipping

    restriced shipping AL AK AR AZ
    AK, AZ Y Y
    AK Y
    AL,AR Y Y
    AK Y

  5. #5
    Registered User
    Join Date
    10-27-2012
    Location
    londan, england
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: look for value in cells in a row, return multiple column names

    the vba code worked. i have been working on this for 3 hours. wish i would have found this forum sooner! Martin is a Genius!

  6. #6
    Forum Contributor
    Join Date
    10-18-2012
    Location
    Telford, England
    MS-Off Ver
    Excel 2010 (2003)
    Posts
    294

    Re: look for value in cells in a row, return multiple column names

    Hint: When I'm building a list with separators like this, I place the separator before each value rather than after. Then throwing away the spurious one is easier as its always first:

    Please Login or Register  to view this content.
    The result should be identical.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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