+ Reply to Thread
Results 1 to 9 of 9

Pull non-blank values from a range and copy those values into one cell separated by commas

  1. #1
    Registered User
    Join Date
    03-29-2015
    Location
    Washington DC
    MS-Off Ver
    Windows Vista
    Posts
    2

    Pull non-blank values from a range and copy those values into one cell separated by commas

    Hello!
    Thanks so much for your help.

    Please see the picture - I have a survey of questions. Not all of the questions will have responses.

    I want to pull only the values from those cells with responses into one cell. And I want those values to be separated by commas.

    I've experimented with index and match with limited success, but I'm thinking I might need isblank and/or other functions.

    I would like a solution in which I can apply this formula to a range as large as 20 questions.

    Thank you!

    Excel_Problem.jpg
    Last edited by ramblinwillie; 03-29-2015 at 11:06 AM.

  2. #2
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: Pull non-blank values from a range and copy those values into one cell separated by co

    Here is a VBA solution (actually, a UDF) from another source. Instructions on how to use it are on that page as well. It is pretty simple to implement following them.

    http://www.vbaexpress.com/kb/getarticle.php?kb_id=817

    - Moo

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Pull non-blank values from a range and copy those values into one cell separated by co

    Install the VBA function from this link:

    https://www.excelforum.com/showthread.php?p=3096647

    Then, to use it:

    Data Range
    A
    B
    C
    D
    E
    1
    Question 1
    Question 2
    Question 3
    Question 4
    Question 5
    2
    Yes
    No
    No
    3
    4
    5
    6
    7
    Yes, No, No


    Enter this array formula** in A7:

    =concatall(IF(A2:E2<>"",A2:E2,""),", ")

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: Pull non-blank values from a range and copy those values into one cell separated by co

    Basically, if you follow the directions from that page you will be inserting VBA code into a new module within that workbook:
    Please Login or Register  to view this content.
    That should do the trick. Once you go back into the Excel view, all you would have to do then is enter this formula in a blank cell (assuming your range is in cells A2:E2):

    =ConcRange(A2:E2)

    * Of course, if you plan to have varying # of responses, you could modify that function to something like:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    That will concatenate all cells in row 2 from A2 thru the last column with a text value in it.

    - Moo
    Last edited by Moo the Dog; 03-29-2015 at 01:43 PM.

  5. #5
    Forum Contributor
    Join Date
    01-14-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    240

    Re: Pull non-blank values from a range and copy those values into one cell separated by co

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Please consider adding a * if I helped.

  6. #6
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: Pull non-blank values from a range and copy those values into one cell separated by co

    Quote Originally Posted by Brendan_Floyde View Post
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    That may work for a couple of cells, Brendan_Floyde, but if there are 10, 20, heck, if there are 50 survey questions, that is going to be one ridiculously long formula. =)

    - Moo

  7. #7
    Registered User
    Join Date
    03-20-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    18

    Re: Pull non-blank values from a range and copy those values into one cell separated by co

    You can use the VBA code people posted before me, but if this is a one time thing that you at the end of your survey, it might be quicker to just copy the results into a good text editor (say Sublime Text) and do a find and replace and paste it back in Excel.

    I often have to do this for thousands of cells (to put as comma separated into an INSERT statement into a DB) and text manipulation in a text editor works wonders.

  8. #8
    Registered User
    Join Date
    03-29-2015
    Location
    Washington DC
    MS-Off Ver
    Windows Vista
    Posts
    2

    Re: Pull non-blank values from a range and copy those values into one cell separated by co

    Thanks to everyone!

    Moo, I used that code and it worked! Thank you! I do have one question - the code only worked when it was saved as a VBA module. And even then it had to be saved as "sai_ConcRange" per the attachment in the zip file found at the bottom of that page. If it was named as "ConcRange", it did not work. Do you have any idea about why that is? What is that "sai_" in front of the module name and why is it required?

    Tony, thank you for that code. I decided not to use it, though, because I found Moo's VBA to be a little simpler. I'm not very good at VBA yet, and the code you sent along is just way above my level at this point. Thanks again, though.

    Brendan - thank you as well. This is the non-VBA solution I was trying to come up with on my own and I see you did it easily. I was trying with match and index, but your solution makes a lot of sense and is very handy for just a few cells.

    dos mios - very clever, thank you. If I'm understanding correctly, you're suggesting doing a find and replace on a tab-delimited file from excel and replacing those with tabs with commas?

    Thanks again to all!
    Last edited by ramblinwillie; 03-31-2015 at 12:37 PM.

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Pull non-blank values from a range and copy those values into one cell separated by co

    You're welcome. We appreciate the feedback!

    If your question has been solved please mark the thread as being solved.

    In the menu bar above the very first post select Thread Tools, then select Mark this thread as solved.

+ 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] Formula to count values in single cell separated by commas
    By aimeecrystalaid in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-25-2017, 01:01 AM
  2. Returning Multiple Values Separated by Commas to a single cell
    By enragedpigeon in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-02-2015, 05:48 PM
  3. [SOLVED] Values separated by Commas - want in separate columns, cells from original cell
    By schmidt62 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-03-2012, 02:50 PM
  4. Replies: 5
    Last Post: 06-05-2012, 03:32 PM
  5. Find a Value In A Table of Cell Each With More Than 2 Values Separated By Commas
    By Misha322 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-28-2012, 02:42 PM

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