+ Reply to Thread
Results 1 to 22 of 22

Look up data from multilple columns and insert in one cell using a comma to seperate

  1. #1
    Registered User
    Join Date
    01-31-2014
    Location
    NY
    MS-Off Ver
    Excel 365
    Posts
    13

    Look up data from multilple columns and insert in one cell using a comma to seperate

    I have a data set that I wish to look up the data from one column and if it is greater then 0 write it in another column separated by commas. Here is an example:

    The data is dates that a service was provided and how many time that day it was done and not everyone gets the service on the same days.
    I would like to summarize the days of the month that service was provided not number of times into 1 cell.


    A B C
    Row 1 November
    Row 2 1 5 15
    Row 3 1 0 2
    Row 4 0 1 3

    November is in A3

    If A2 is greater then 0 I want to write A1 A2
    If A2 and A3 is greater then 0 I want to write A1 A2, A3
    If A2 is 0 and B2 is greater then 0, I want to write A1 B2

    I have been battling this for days any help would be great
    Thanks

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    Hi and welcome to the forum

    I think you'd better upload the workbook example. Your explanation is not clear - at least to me.
    Show clearly which cells are original data and which cells are the results.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    01-31-2014
    Location
    NY
    MS-Off Ver
    Excel 365
    Posts
    13

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    a b c d
    1 Month November
    2 Date 1 3 5
    3
    4 Jay 0 1 1 In this case I would want to write November 3,5
    5 John 1 1 1 In this case I would want to write November 1,3,5
    6 Roger 1 0 0 In this case I would want to write November 1
    7 Frank 0 1 0 In this case I would want to write November 3

    I don't know how to upload the workbook. Is this a little clearer, its my actual data. The numbers next to the names mean I provided the service. 0 means I did not and the one means I was there 1 time that day.
    What I want written as I wrote next to the data is that I was there in November on days x,y,z.
    Is this a little clearer?
    Thanks

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    Hi,

    A workbook is clearer. I still don't understand whether those numbers/names are in a single column or several columns

    Check the FAQ section 'Reading & Posting messages' to see how to attach a workbook.

  5. #5
    Registered User
    Join Date
    01-17-2014
    Location
    Charlotte, NC
    MS-Off Ver
    Office 2007 & 2010
    Posts
    3

    Cool Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    Month November
    Date 1 3 5

    Jay 0 1 1 November 3, 5
    John 1 1 1 November 1, 3, 5
    Roger 1 0 0 November 1
    Frank 0 1 0 November 3
    Bill 0 0 1 November 5
    Mike 1 0 1 November 1, 5
    Jacob 2 1 0 November 1, 3

    Here is a solution using an IF statement:
    =IF(AND(B4>0,C4>0,D4>0),$B$1&" "&$B$2&", "&$C$2&", "&$D$2,IF(AND(B4>0,C4>0),$B$1&" "&$B$2&", "&$C$2,IF(AND(C4>0,D4>0),$B$1&" "&$C$2&", "&$D$2,IF(AND(B4>0,D4>0),$B$1&" "&$B$2&", "&$D$2,IF(AND(B4>0,C4=0,D4=0),$B$1&" "&$B$2,IF(AND(B4=0,C4>0,D4=0),$B$1&" "&$C$2,IF(AND(B4=0,C4=0,D4>0),$B$1&" "&$D$2,"")))))))

    This accounts for all scenarios that may result when there are three Dates in one month. If additional Dates were added, this IF statement would need significant expansion.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    01-31-2014
    Location
    NY
    MS-Off Ver
    Excel 365
    Posts
    13

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    THANKS!! That look like what I was getting at.
    That's quite an IF string

  7. #7
    Registered User
    Join Date
    01-31-2014
    Location
    NY
    MS-Off Ver
    Excel 365
    Posts
    13

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    and of course, I have a month with more then 3 days. I'' see what I can figure out

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    You may find the attached which uses a UDF more flexible if you have many dates.

    In a cell enter the function =DAYS()
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    01-31-2014
    Location
    NY
    MS-Off Ver
    Excel 365
    Posts
    13

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    Thanks, that is way above my head, How do I insert that into my spreadsheet?

  10. #10
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    Hi,

    If you're not familiar or uncomfortable with using macros and the Visual Basic Environment then it may be better to upload your workbook and we'll happily add the functionality.

    If you are happy to incorporate it yourself, note that there is a dynamic range name that has been added, viz. 'lstDates', then copy the Function Days() that you'll find in the VBE of the example into your workbook.

  11. #11
    Registered User
    Join Date
    01-31-2014
    Location
    NY
    MS-Off Ver
    Excel 365
    Posts
    13

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    Thank you again, I have attempted to upload the workbook.
    Attached Files Attached Files

  12. #12
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    Hi,

    This of course is different to your example since you now have several months. It's always a good idea to ensure examples exactly mimic the real data.

    Would you manually enter the results you expect to see in the real workbook and re-upload it.

  13. #13
    Registered User
    Join Date
    01-31-2014
    Location
    NY
    MS-Off Ver
    Excel 365
    Posts
    13

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    that is my actual workbook. As it stands today. The service provided is snow removal so its hard to determine the number of columns ( days of the month). I thought if I had a base I could build from there by inserting columns as I need them. If you use this set as an example can I insert columns with in the parameters of this base and have it still work?
    The data shouldn't extend past March but how many days no one knows.
    sorry for the misleading example, I did not realize how complex this was
    Thanks again

  14. #14
    Registered User
    Join Date
    01-17-2014
    Location
    Charlotte, NC
    MS-Off Ver
    Office 2007 & 2010
    Posts
    3

    Cool Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    You're welcome.

    After thinking through the limitations of the IF statement, I came up with a solution that uses a VBA macro and button to perform the same function more dynamically. This solution would allow you to add dates, and/or add users to your example without having to worry about updating an IF statement and copying it each time you change the variables. When using IF statements, it would not only be tedious each time you make updates, but eventually you will run into the argument limit in Excel as each date added would exponentially increase the number of IF statements required.

    In the attached example, I've created a button (at the top right), which is tied to a VBA macro (CompleteVisits) that when pressed will instantly update the values in the column containing "Visits On:" in row 3. Try adding a name, and/or dates across the top, then complete the data and press the Complete Visits button.

    NOTE: When you add a date in row 2, be sure to add a column so that you always have a blank column to the right of your data.

    Check out the attachment (macro-enabled) for this more in-depth solution.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    01-17-2014
    Location
    Charlotte, NC
    MS-Off Ver
    Office 2007 & 2010
    Posts
    3

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    This example does not account for multiple months. Only multiple days within a month.

  16. #16
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    Hi,

    What I meant was that your original example only had one base month. Your latest has several months. I need to understand where you want to see the final output and what the layout is. Just add some manual results to the workbook.

    At the moment it's not clear whether it's one result column that has say "March 1, 5, 8, 20, April 3, 4, 5, 6, May 2, 3, 4" etc. or separate monthly columns. So to avoid any doubt it is much better with all these things if you just show us with an exact result. That way we all avoid wasting our time.

  17. #17
    Registered User
    Join Date
    01-31-2014
    Location
    NY
    MS-Off Ver
    Excel 365
    Posts
    13

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    Thank you for clarifying that. The second file (the larger one) should be the way I want it to look.
    Attached Files Attached Files

  18. #18
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    Hi,

    See attached
    Attached Files Attached Files

  19. #19
    Registered User
    Join Date
    01-31-2014
    Location
    NY
    MS-Off Ver
    Excel 365
    Posts
    13

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    Hello Richard,

    That attached file does not appear to be working.

  20. #20
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    Hi,

    In what way isn't it working?

    Have you answered 'Yes' to Enable Macros when you are prompted on opening the file. It contains a User Defined Function (macro).

  21. #21
    Registered User
    Join Date
    01-31-2014
    Location
    NY
    MS-Off Ver
    Excel 365
    Posts
    13

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    its telling me compile error, variable not defined when visual basic opens
    yes I did tell it to enable macros

  22. #22
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Look up data from multilple columns and insert in one cell using a comma to seperate

    How weird.

    I'd missed the fact that you're using Excel 2003 and had put this together with Excel 2010 without encountering a problem.

    And you are quite correct, When I open it with my 2003 it does debug as you point out. The reason is that the variable lRow has not bee declared.
    So if you add a new

    Dim lRow As Long

    you should be OK.

    What is now puzzling me though is why my Excel 2010 didn't debug. The 2010 VBA option to 'Require variable declaration' is set so it too should have tripped up. I have a bit more detective work to do!

+ 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] Split comma separated text and insert into next row retaining all other columns.
    By saidineshbabu in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-17-2013, 03:25 AM
  2. [SOLVED] Changing font for multilple columns based on what is diplayed in another cell
    By Franklic in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-11-2012, 11:24 AM
  3. [SOLVED] Seperate Comma seperated values in seperate rows in different tab of same worksheet
    By amlan009 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-28-2012, 04:54 AM
  4. columns to data that have separated by comma to seperate cell
    By naflas in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2012, 12:13 AM
  5. How to seperate data in a cell which is split by a comma
    By Eamonn in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-29-2006, 04:35 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