![]() |
SUBSTITUTE multiple text strings
I have a column of concatenated text, and would like to add another column
that "deletes" certain strings of characters if it is found in the concatenated column. For example, if text strings of "xx" or "yy" are found, I want those characters to be deleted. So, WWXX would just show as WW; YYZZ would just show as ZZ. I found I can use the substitute function to search for just one string: =SUBSTITUTE(A2,"XX,""). Can I modify this formula to perform the replacement if XX or YY is found? |
Answer: SUBSTITUTE multiple text strings
Yes, you can modify the formula to perform the replacement if XX or YY is found by using the nested SUBSTITUTE function. Here's how you can do it:
Note that this formula is case-sensitive, so it will only remove "XX" and "YY" if they are in uppercase. If you want to remove them regardless of case, you can use the UPPER function to convert the text to uppercase before applying the SUBSTITUTE function. For example: Formula:
|
SUBSTITUTE multiple text strings
Looks like this works. The second SUBSTITUTE function passes its result
to the previous one, kinda like an OR. =SUBSTITUTE(SUBSTITUTE(A2,"XX",""),"YY","") You can probably nest as many as needed. I didn't test for limits. For example, it isn't case sensitive, so to replace both upper and lower case, use 4 levels of nesting. =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,"y y",""),"xx",""),"XX",""),"YY","") Len richzip wrote: I have a column of concatenated text, and would like to add another column that "deletes" certain strings of characters if it is found in the concatenated column. For example, if text strings of "xx" or "yy" are found, I want those characters to be deleted. So, WWXX would just show as WW; YYZZ would just show as ZZ. I found I can use the substitute function to search for just one string: =SUBSTITUTE(A2,"XX,""). Can I modify this formula to perform the replacement if XX or YY is found? |
SUBSTITUTE multiple text strings
it isn't case sensitive, so to replace both upper and lower case, use 4
levels of nesting. I think you meant it is case sensitive (which it is) but you don't need to nest 4 levels. Try it like this: =SUBSTITUTE(SUBSTITUTE(UPPER(A2),"XX",""),"YY","") Also note that if the string is XXXZZZ The result will be XZZZ -- Biff Microsoft Excel MVP "LenB" wrote in message ... Looks like this works. The second SUBSTITUTE function passes its result to the previous one, kinda like an OR. =SUBSTITUTE(SUBSTITUTE(A2,"XX",""),"YY","") You can probably nest as many as needed. I didn't test for limits. For example, it isn't case sensitive, so to replace both upper and lower case, use 4 levels of nesting. =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,"y y",""),"xx",""),"XX",""),"YY","") Len richzip wrote: I have a column of concatenated text, and would like to add another column that "deletes" certain strings of characters if it is found in the concatenated column. For example, if text strings of "xx" or "yy" are found, I want those characters to be deleted. So, WWXX would just show as WW; YYZZ would just show as ZZ. I found I can use the substitute function to search for just one string: =SUBSTITUTE(A2,"XX,""). Can I modify this formula to perform the replacement if XX or YY is found? |
SUBSTITUTE multiple text strings
On Wed, 30 Jan 2008 20:26:10 -0800, richzip
wrote: I have a column of concatenated text, and would like to add another column that "deletes" certain strings of characters if it is found in the concatenated column. For example, if text strings of "xx" or "yy" are found, I want those characters to be deleted. So, WWXX would just show as WW; YYZZ would just show as ZZ. I found I can use the substitute function to search for just one string: =SUBSTITUTE(A2,"XX,""). Can I modify this formula to perform the replacement if XX or YY is found? How many different types of strings will need to be deleted? If it is less than eight, you can nest SUBSTITUTE functions. --ron |
SUBSTITUTE multiple text strings
If it is less than eight, you can nest SUBSTITUTE functions.
If you're using Excel 2007 you can nest up to 64 levels plus the top level = 65. One of these days I'm going to try that out just to see what it looks like! -- Biff Microsoft Excel MVP "Ron Rosenfeld" wrote in message ... On Wed, 30 Jan 2008 20:26:10 -0800, richzip wrote: I have a column of concatenated text, and would like to add another column that "deletes" certain strings of characters if it is found in the concatenated column. For example, if text strings of "xx" or "yy" are found, I want those characters to be deleted. So, WWXX would just show as WW; YYZZ would just show as ZZ. I found I can use the substitute function to search for just one string: =SUBSTITUTE(A2,"XX,""). Can I modify this formula to perform the replacement if XX or YY is found? How many different types of strings will need to be deleted? If it is less than eight, you can nest SUBSTITUTE functions. --ron |
SUBSTITUTE multiple text strings
thanks everyone ..it worked perfectly!
"T. Valko" wrote: If it is less than eight, you can nest SUBSTITUTE functions. If you're using Excel 2007 you can nest up to 64 levels plus the top level = 65. One of these days I'm going to try that out just to see what it looks like! -- Biff Microsoft Excel MVP "Ron Rosenfeld" wrote in message ... On Wed, 30 Jan 2008 20:26:10 -0800, richzip wrote: I have a column of concatenated text, and would like to add another column that "deletes" certain strings of characters if it is found in the concatenated column. For example, if text strings of "xx" or "yy" are found, I want those characters to be deleted. So, WWXX would just show as WW; YYZZ would just show as ZZ. I found I can use the substitute function to search for just one string: =SUBSTITUTE(A2,"XX,""). Can I modify this formula to perform the replacement if XX or YY is found? How many different types of strings will need to be deleted? If it is less than eight, you can nest SUBSTITUTE functions. --ron |
SUBSTITUTE multiple text strings
On Thu, 31 Jan 2008 12:50:12 -0500, "T. Valko" wrote:
If it is less than eight, you can nest SUBSTITUTE functions. If you're using Excel 2007 you can nest up to 64 levels plus the top level = 65. One of these days I'm going to try that out just to see what it looks like! -- Biff Microsoft Excel MVP I can't imagine not using VBA if I had something that complex. --ron |
SUBSTITUTE multiple text strings
Sigh, yes you are right, I meant that it is case sensitive. Thanks for
th correction. I tried to point it out only because the OP mentioned "xx" in one sentence, then showed "XX" in his example. I like your way using UPPER, as long as it is ok to change the result to upper case. Len T. Valko wrote: it isn't case sensitive, so to replace both upper and lower case, use 4 levels of nesting. I think you meant it is case sensitive (which it is) but you don't need to nest 4 levels. Try it like this: =SUBSTITUTE(SUBSTITUTE(UPPER(A2),"XX",""),"YY","") Also note that if the string is XXXZZZ The result will be XZZZ |
All times are GMT +1. The time now is 09:43 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com