Formula to convert text based on commas

Nola111

Board Regular
Joined
Aug 28, 2013
Messages
115
I'm trying to use a formula which would take what's in the column A and convert it to what's in column B. Basically, the entire contents would end up surrounded by square brackets, and anywhere there is a comma, this comma should act as a separator, and finally all phrases separated by commas should be enclosed in parentheses. It would look like this:

AB
1
Advocate Agriculturist, 1996 - 2001 Union Councilor, Mangalur Union, District Secretary (A.I.A.D.M.K.) from 2004 : Cuddalore District, Tamil Nadu, Sports, Games and Tourism

<tbody>
</tbody>
["Advocate Agriculturist, 1996 - 2001 Union Councilor", "Mangalur Union", "District Secretary (A.I.A.D.M.K.) from 2004 : Cuddalore District", "Tamil Nadu", "Sports", "Games and Tourism"]

<tbody>
</tbody>
2
Agriculturist Businessperson, Builder, 1990-95 & 95-97 Corporator, Parola Nagarpalika (Two Terms), , Agriculture and defence affairs

<tbody>
</tbody>
["Agriculturist Businessperson", "Builder", "1990-95 & 95-97 Corporator", "Parola Nagarpalika (Two Terms)", "Agriculture and defence affairs"]

<tbody>
</tbody>
3
Social Worker Agriculturist, Educationist, May, 2014 Elected to 16 th Lok Sabha, , Agriculture and rural development, human resources management, education, sports, international trade and economics, E-governance and strategy, promotion of primary education

<tbody>
</tbody>
["Social Worker Agriculturist", "Educationist", "May", "2014 Elected to 16 th Lok Sabha", "Agriculture and rural development", "human resources management", "education", "sports", "international trade and economics", "E-governance and strategy", "promotion of primary education"]

<tbody>
</tbody>
4
President of Istanbul

<tbody>
</tbody>
["President of Istanbul"]

<tbody>
</tbody>

<tbody>
</tbody>

Note in row 4, if there are no commas, we would just want the phrase in quotes and brackets.

How would I accomplish this with a formula? Is this done with some combination of Substitute and Trim?

Thanks!
 

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
7,792
Office Version
365
Platform
Windows
This will work for your examples:

="["""&SUBSTITUTE(SUBSTITUTE(A1,", ,",","),", ",""", """)&"""]"
 

Nola111

Board Regular
Joined
Aug 28, 2013
Messages
115
This will work for your examples:

="["""&SUBSTITUTE(SUBSTITUTE(A1,", ,",","),", ",""", """)&"""]"
Thanks Steve!

One more question - how would the formula change if I wanted to remove the space after each comma in column B? I tried tinkering with your formula but just kept screwing it up. I'm too much a novice at these formulas, unfortunately.
 
Last edited:

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
7,792
Office Version
365
Platform
Windows
If you look at the formula, the last comma in it has a space after it. Remove that space.
 

Forum statistics

Threads
1,082,153
Messages
5,363,459
Members
400,737
Latest member
urhen22

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top