+ Reply to Thread
Results 1 to 15 of 15

Formula to create new rows when a cell has specific text beyond a comma

  1. #1
    Registered User
    Join Date
    11-10-2014
    Location
    Bradford, England
    MS-Off Ver
    2019
    Posts
    43

    Formula to create new rows when a cell has specific text beyond a comma

    Hi all,

    Really need your help on creating a formula (not a macro) for this which I have tried to solve for ages.


    Currently, every row is a unique activity with its own activity ID in column A.

    Column D lists one or more categories of issues patients face when accessing a service. If there is more than one category, in each cell, the categories are then separated by a comma within the same cell.

    What I need is a formula which does the following:

    a. there is only one category in D (with no commas), then it be copied into column E.
    b. However if Column D holds more than one category which is separated by a comma, then the formula takes the categories beyond the first category and comma and puts it on new seperate rows which copies all the data in the other rows but copies the other categories seperately into Column E.
    c. Each cell can have upto 40 categories and therefore upto 39 more rows for that activity.

    I have attached an excel spreadsheet as an example to show how I would like it to work.


    Activity ID Activity Date Sentiment Options Option Breakdown
    3380 1.00 13/04/2015 Really good Service Diagnosis Diagnosis
    3384 0.00 01/04/2015 Good but not great Service Coordination, Quality of Treatment Service Coordination
    3384 1.00 01/04/2015 Good but not great Service Coordination, Quality of Treatment Quality of Treatment
    3385 0.00 15/04/2015 Excellent needs work Admission, Complaints Process, Quality of Treatment Admission
    3385 0.00 15/04/2015 Excellent needs work Admission, Complaints Process, Quality of Treatment Complaints Process
    3385 15/04/2015 Excellent needs work Admission, Complaints Process, Quality of Treatment Quality of Treatment


    Im looking for a life saver here as this I have been trying to work this out for ages.


    A massive thank you in advance.

    Kind Regards
    Last edited by hionman; 03-23-2017 at 09:01 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: Formula to create new rows when a cell has specific text beyond a comma

    Attaching a sample workbook enables others to work on your problem:

    To attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include BEFORE/AFTER sheets if needed to show the process you're trying to complete or automate. Remember to desensitize the data.

    Click on GO ADVANCED and click "manage attachments" to open the upload window.


    To add a file to a post

  3. #3
    Registered User
    Join Date
    11-10-2014
    Location
    Bradford, England
    MS-Off Ver
    2019
    Posts
    43

    Re: Formula to create new rows when a cell has specific text beyond a comma

    Hi all,

    I have attached a sample excel spreadsheet to show how I would like the formula to work.
    Attached Files Attached Files

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,959

    Re: Formula to create new rows when a cell has specific text beyond a comma

    I'm not sure I followed you. I have assumed that when you said "rows", you meant "columns".

    In E2, copied across and down:

    =TRIM(MID(SUBSTITUTE(","&$D2,",",REPT(" ",125)),125*COLUMNS($A:A),125))
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  5. #5
    Registered User
    Join Date
    11-10-2014
    Location
    Bradford, England
    MS-Off Ver
    2019
    Posts
    43

    Re: Formula to create new rows when a cell has specific text beyond a comma

    Hi Glenn,

    Thanks for the response.

    No i did mean new rows.

    So essentially what I wanted was that rather than have a formula to break down each category after the comma into a new column that I wanted it to be put on a new row underneath it.

    The example I provided was how I wanted it to look after I would have a formula working.

    The new excel file I have attached shows two sheets what the spreadsheet looks like now and what I want it to look like after I have a formula that works to do what I want.

    Really appreciate the help.

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,959

    Re: Formula to create new rows when a cell has specific text beyond a comma

    Hi there. i had to create a helper column to get this to work. Please check that it is doing what you want...
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    11-10-2014
    Location
    Bradford, England
    MS-Off Ver
    2019
    Posts
    43

    Re: Formula to create new rows when a cell has specific text beyond a comma

    Hi Glenn,

    Thanks for this but theres a problem.

    Because you provided the solution on the same sheet, I tried to replicate the formulas by putting the original data on one sheet and the formulas you created on another sheet (I ammended the formula to reflect that some of data was on different sheets).

    I needed to do this as I need all the data on one sheet because I am using that data for a pivot table.

    Anyway when I applied your formula on a different sheet which I pressed ctrl, shift and enter because they were array formulas, all it showed was 0s. I don't know if its a formatting problem, even though Ive tried to check if it is but can't get my head around why it isn't showing the data.

    I have attached the example I am working on - I have put the formulas in the 'After' sheet, which pulls the data from 'Sheet1'.

    I would really appreciate it if you could tell me whats gone wrong as I really need this to work.

    A Massive thank you in advance.
    Attached Files Attached Files

  8. #8
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,959

    Re: Formula to create new rows when a cell has specific text beyond a comma

    That was lazy of me... here you go. The problem is that not all of the ranges had to apply to the "Before" sheet. Some of them had to go with the formula.
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,133

    Re: Formula to create new rows when a cell has specific text beyond a comma

    Try
    =IFERROR(INDEX(Sheet1!A$2:A$5,MATCH(0,--(COUNTIF($A$1:$A1,Sheet1!$A$2:$A$5)=Sheet1!$F$2:$F$5),0)), "")

  10. #10
    Registered User
    Join Date
    11-10-2014
    Location
    Bradford, England
    MS-Off Ver
    2019
    Posts
    43

    Re: Formula to create new rows when a cell has specific text beyond a comma

    This is brilliant - thanks glenn - one last favour - is there a formula which automatically counts the amount of phrases to automate the Helper column instead of doing it manuallly.

    For example, if there there are 10 categories the helper column will automatically recognise that it contains 10 categories.

    A BIG THANK YOU IN ADVANCE.

  11. #11
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,959

    Re: Formula to create new rows when a cell has specific text beyond a comma

    Hahaha. I think you DO need the helper. However, in my haste yesterday, I forgot to add the formula that calculates the helper. Now done.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    04-08-2017
    Location
    BKK
    MS-Off Ver
    Office 2016
    Posts
    23

    Re: Formula to create new rows when a cell has specific text beyond a comma

    Hi Glenn,

    That is a very neat formula. Some of the formula used "REPT", is something i didnt used before.

    Anyway I've similar issues with @hionman but instead of writing a formula, is there a way i can automate it with VBA or etc?
    Would you suggest using VBA or the formula used in this example.

    I've less than a million of records and this task is probably done every quarter.

    Cheers
    Henry

  13. #13
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,133

    Re: Formula to create new rows when a cell has specific text beyond a comma

    @Ohhaa

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

  14. #14
    Registered User
    Join Date
    04-08-2017
    Location
    BKK
    MS-Off Ver
    Office 2016
    Posts
    23

    Re: Formula to create new rows when a cell has specific text beyond a comma

    @John,

    So sorry about that. Let me create a new thread on this

  15. #15
    Registered User
    Join Date
    04-08-2017
    Location
    BKK
    MS-Off Ver
    Office 2016
    Posts
    23

    Re: Formula to create new rows when a cell has specific text beyond a comma

    Hi Glenn,

    Would you be so kind to look at a similar question I've at this thread.
    https://www.excelforum.com/excel-for...y-a-comma.html

    Appreciate your help

+ 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] Need Macro To Create New Rows Based on Comma Separted Values in Cell
    By alex20850x in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-28-2016, 05:15 PM
  2. Replies: 10
    Last Post: 04-11-2014, 03:11 PM
  3. Macro splitting comma delimated cell text into rows with other row data copied...
    By geoffffffff in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-13-2013, 11:07 AM
  4. Find and remove all text to the left of last comma (including comma) in a cell
    By Excelrookie_1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-05-2013, 08:47 AM
  5. Replies: 3
    Last Post: 02-16-2013, 06:10 PM
  6. [SOLVED] Macro to find specific text in a cell and then create multiple rows above
    By Willardio in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-21-2012, 09:52 AM
  7. [SOLVED] Formula for adding a comma in front of text in a cell
    By Shelley in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-18-2005, 12:06 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