Cutting Up Text by Commas

nirvehex

Well-known Member
Joined
Jul 27, 2011
Messages
505
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a string of text in one cell, BW11 - "Color Change, Shape Same, Freq Decrease, Material Same, Game Same"

This phrase can alter based on other factors.

Essentially, what I'm trying to do is any where there is a comma, look back and see the first word. If it says same, do not copy, if it says decrease or increase or reduction, or any other word besides same it would copy it.

So in this case in BX11 I would want it to read "Color Change, Freq Decrease". So anything that is not changing or increasing or decreasing would be left out.

Is there a way to do this with mid, or left or substitute functions?

Thanks!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I don't know about how to do this with built in excel functions. You can create your own function.
Code:
Function myFunction(cell)
MySplit = split(cell, ", ")
For each i in mySplit(i)
mySplitAgain = spLit(mySplit(i)," ")
If lcase(mySplitAgain(1)) <>"same" then
Output = output & ", "&mySplit(i)
END if
i = i + 1
Next
myFunction = trim(mid(output,2,Len(output)-2))
END function
What this is saying is split the cell value by a comma and space delimiter.
Then split each split value again by a space. Read the second split value and if it doesn't equal "same", then add it to the output string.
Just type =myFunction(BW11) in whatever cell you want. There may be some syntax errors in my code that you will have to correct because I did this from memory and didn't test it.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,222,383
Messages
6,165,659
Members
451,983
Latest member
Raph24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top