Separate words with commas in Excel 2010 -


i'm trying use formula in excel separate bunch of words in cell comma. if there more 5 words in cell, want first 5 words. first 5 words in cell , separate them comma use this:

=substitute(left(a1,find("^",substitute(a1," ","^",5))-1), " ", ", ") 

this works fine. problem this, because of number 5 here, if cell contains less 5 words, error. tried substitute 5 this:

len(trim(a1))-len(substitute(a1," ",""))+1 

so function becomes this:

=substitute(left(a1,find("^",substitute(a1," ","^",len(trim(a1))-len(substitute(a1," ",""))+1))-1), " ", ", ") 

but doesn't work, gives me error. idea how can please?

also ignore first word if first character "-" (without quotes) , start second word. in other words, want this:

i love life should return i, love, my, life, very
- love life should return i, love, my, life, (the "-" ignored")
love should return i, love, my

thanks in advance help

here's different approach. aside "less 5" issue, deals "5 words no space @ end" issue:

=left(a1,find("^",substitute(a1 & "^"," ","^",5))-1) 

edit 1: noticed part leading "- ". addition isn't elegant, deals it, , trims trailing spaces:

=trim(left(if(left(a1,2)="- ",mid(a1,3,999),a1),find("^",substitute(if(left(a1,2)="- ",mid(a1,3,999),a1) & "^"," ","^",5))-1)) 

edit 2: oh yeah, commas:

=substitute(trim(left(if(left(a1,2)="- ",mid(a1,3,999),a1),find("^",substitute(if(left(a1,2)="- ",mid(a1,3,999),a1) & "^"," ","^",5))-1))," ",",")  

enter image description here


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -