+ Reply to Thread
Results 1 to 11 of 11

Copy Multiple Column Headers to single cell if conditions met

  1. #1
    Registered User
    Join Date
    05-06-2014
    Location
    Salt Lake City, UT
    MS-Off Ver
    Excel 2013
    Posts
    10

    Copy Multiple Column Headers to single cell if conditions met

    I have a large list of sales info that tabulates who bought which books. The book titles are listed as headers, with a "1" in the corresponding row to show which email purchased which book. I'd like to take the book titles and combine into one cell, separated by commas, like so: book1, book2, book3. This way, there will be one column summarizing all the books someone bought in one cell.

    Here is small table to represent what I'm trying to do. Please keep in mind that I have over 30 columns and 16,000 rows so a simple IF and Concatenate function will not work. I'd like to have the values appear in the Book Summary column.

    Thanks for all your help!

    What I have currently:
    Name Book Summary Book Title 1 Book Title 2 Book Title 3
    [email protected] 1 1
    [email protected] 1
    [email protected] 1 1


    What I Seek:
    Name Book Summary Book Title 1 Book Title 2 Book Title 3
    [email protected] book1, book2 1 1
    [email protected] book2 1
    [email protected] book2, book3 1 1

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

    Re: Copy Multiple Column Headers to single cell if conditions met

    You can do this with a VBA function. Are you OK with that?
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Copy Multiple Column Headers to single cell if conditions met

    Hello,

    Try this macro.
    Assuming data starts in cell A1 :

    Please Login or Register  to view this content.
    Last edited by GC Excel; 06-20-2015 at 09:30 PM. Reason: typo in macro
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  4. #4
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Copy Multiple Column Headers to single cell if conditions met

    Since you have 16000 lines, better use this version, otherwise seems to have an error with the Application.Index limit.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-06-2014
    Location
    Salt Lake City, UT
    MS-Off Ver
    Excel 2013
    Posts
    10

    Re: Copy Multiple Column Headers to single cell if conditions met

    I've never messed with VBA but am game to try.

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

    Re: Copy Multiple Column Headers to single cell if conditions met

    Try this...

    Copy the code at the link below and paste it in a general module.

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

    Then, assuming this is your data...

    Data Range
    A
    B
    C
    D
    E
    F
    1
    Name
    Summary
    Book1
    Book2
    Book3
    Book4
    2
    Name1
    Book2, Book4
    1
    1
    3
    Name2
    Book1, Book3
    1
    1
    4
    Name3
    Book1
    1
    5
    Name4
    Book4
    1


    Enter this array formula** in B2 and copy down as needed:

    =concatall(IF(C2:F2=1,C$1:F$1,""),", ")

    ** 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.

    You'll have to save the file as a macro enabled file in the *.xlsm format.

  7. #7
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Copy Multiple Column Headers to single cell if conditions met

    I've never messed with VBA but am game to try.
    Here's how to do it :
    1. with you file opened, press ALT+F11 to open the VBA editor
    2. The, ALT, I, M to insert a new module
    3. Copy / Paste the code in this module
    4. Press F5 to run the code

  8. #8
    Registered User
    Join Date
    05-06-2014
    Location
    Salt Lake City, UT
    MS-Off Ver
    Excel 2013
    Posts
    10

    Re: Copy Multiple Column Headers to single cell if conditions met

    Quote Originally Posted by Tony Valko View Post
    Try this...

    =concatall(IF(C2:F2=1,C$1:F$1,""),", ")
    Thank you for referencing the UDF concatAll. I was able to get the formula to concat an entire row, leaving out the blanks. However, the conditional IF that you added returns a #Name error. Any insight as to why this may be happening?

    Thanks again!

  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: Copy Multiple Column Headers to single cell if conditions met

    Are you sure you put the code in the right place?

    Here's a sample file that demonstrates this.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    05-06-2014
    Location
    Salt Lake City, UT
    MS-Off Ver
    Excel 2013
    Posts
    10

    Re: Copy Multiple Column Headers to single cell if conditions met

    Thanks Tony Valko, that function helped organize all the data.
    Last edited by eadamquinn; 07-07-2015 at 11:34 PM. Reason: I found my answer

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

    Re: Copy Multiple Column Headers to single cell if conditions met

    You're welcome. Thanks for 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. SUMIFs With Multiple Not Equal To Conditions In a Single Column
    By 5150 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 04-14-2015, 12:08 PM
  2. [SOLVED] copy multiple column, including headers, to a new sheet
    By boboivan in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-16-2015, 05:43 AM
  3. Replies: 15
    Last Post: 01-24-2014, 06:32 PM
  4. Replies: 0
    Last Post: 09-11-2013, 09:54 AM
  5. [SOLVED] Multiple formulas in column with reference to single cell - Copy Issue
    By MarVil85 in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 06-21-2012, 02:44 PM

Tags for this Thread

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