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

hionman

New member
Joined
Nov 11, 2014
Messages
3
Reaction score
0
Points
0
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 IDActivity DateSentimentOptionsOption Breakdown
338013/04/2015Really good ServiceDiagnosisDiagnosis
338401/04/2015Good but not greatService Coordination, Quality of TreatmentService Coordination
338401/04/2015Good but not greatService Coordination, Quality of TreatmentQuality of Treatment
338515/04/2015Excellent needs workAdmission, Complaints Process, Quality of TreatmentAdmission
338515/04/2015Excellent needs workAdmission, Complaints Process, Quality of TreatmentComplaints Process
338515/04/2015Excellent needs workAdmission, Complaints Process, Quality of TreatmentQuality 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​




 
Have a look at the attached...

If you don't want to use VBA, then you will need to create a separate table of results.

So assuming your original table looks like what I've got in column A: D, then

Add some helper columns..

In E2, add formula to count number of comma separated entries in column D:

=LEN(D2)-LEN(SUBSTITUTE(D2,",",""))+1 copied down

In F2, add formula to do a cumulative count of comma separated entries in order to know how many total new rows are needed...

=SUM(E$2:E2) copied down

Now, for results table

In K2 to get duplicated IDs

=IF(ROWS(K$2:K2)>MAX($F$2:$F$4),"",INDEX($A$2:$A$4,MIN(IF(ROWS(K$2:K2)<=$F$2:$F$4,ROW($A$2:$A$4)-ROW($A$2)+1)))) this is an array formula and must be confirmed with CTRL+SHIFT+ENTER not just ENTER, then copied down as far as needed to get all duplicated rows.

In L2 to get remaining columns of info in duplicate.

=IF($K2="","",INDEX($B$2:$D$4,MATCH($K2,$A$2:$A$4,0),COLUMNS($L2:L2)))
copied down and across 2 more columns to N.

In O2, to separate the Options.

=TRIM(MID(SUBSTITUTE(N2,",",REPT(" ",100)),1+(100*(COUNTIF(K2:K$2,K2)-1)),100))
copied down

Note: You can Cut/Paste the results table to sheet 2 if desired.

Adjust all ranges/references to suit your actual data. For array formulas you must reconfirm with CTRL+SHIFT+ENTER after any changes.

Hope this helps.
 

Attachments

  • Create duplicating rows.xlsx
    10.3 KB · Views: 6
Test this puppy had to do it on the fly, think its fine. Will not be around for a few hours so if you need it tweaked it will be later this evening.

Knock 'em dead Tiger!

https://www.screencast.com/t/ujHROol7Rnp

Excel attached
 

Attachments

  • 2017-03-23_Patient.xlsm
    65.9 KB · Views: 8
A Minor Tweak, use this one instead, did not see that you had 39 lines potentially

attached

Too much coffee uploaded wrong version use _1
 

Attachments

  • 2017-03-23_Patient.xlsm
    67.9 KB · Views: 7
  • 2017-03-23_Patient_1.xlsm
    67.9 KB · Views: 6
Last edited:
Back
Top