Searching if a specific character exists afer nth occurrence of a value

johnmerlino

Board Regular
Joined
Sep 21, 2010
Messages
94
Hey all,

I have the two formulas I want to apply if the condition is true or false. Problem is I need to determine whether there's a comma after the second ampersand in a cell.

For example, if the field looks like this:
Code:
HernaraMartin,Harry & Marie Anne & Ann Sally
then I want to execute this formula:
Code:
=CONCATENATE(LEFT(A30,FIND(",",A30)-1),",",TRIM(MID(A30,FIND("&",A30,FIND("&",A30)+1)+1,LEN(A30))))

which produces this:
Code:
HernaraMartin,Ann Sally

Now if the cell looks like this:
Code:
HernaraMartin,Harry & Marie Anne & Jenners,Sally
Since there's a comma after second ampersand, I want to execute this:
Code:
=TRIM(RIGHT(A32,LEN(A32)-FIND("*",SUBSTITUTE(A32,"&","*",LEN(A32)-LEN(SUBSTITUTE(A32,"&",""))))))
which outputs this:
Code:
Jenners,Sally
Problem is how to determine whether a comma exists after that second ampersand.

Thanks for response.
 
I figured it out:
Code:
=IF(ISNUMBER(FIND(",",MID(A30,FIND("&",A30,FIND("&",A30)+1)+1,LEN(A30)))),TRIM(RIGHT(A30,LEN(A30)-FIND("*",SUBSTITUTE(A30,"&","*",LEN(A30)-LEN(SUBSTITUTE(A30,"&","")))))),CONCATENATE(LEFT(A30,FIND(",",A30)-1),",",TRIM(MID(A30,FIND("&",A30,FIND("&",A30)+1)+1,LEN(A30)))))
 
Upvote 0
Try something like...

=IF(ISNUMBER(FIND(",",REPLACE(A30,1,FIND("#",SUBSTITUTE(A30,"&","#",2)),""))),1,0)

Replace 1 and 0 with appropriate expressions.
 
Upvote 0
great, another problem. If it doesn't meet any of these conditions, then I get VALUE! error, when I just want cell to be empty.
 
Upvote 0
Hi

If there are a maximum of 2 ampersands, as in the examples you can use:

=ISNUMBER(SEARCH("*&*&*,",A1))
 
Upvote 0
Both my solution and Aladin's work. The problem now is I get a VALUE error if neither of the conditions are true. Is there a way to default it to "" an empty space if neither condition is true?

In other words, if it doesn't contain two ampersands, then default to ""
 
Last edited:
Upvote 0
ok this ultimately worked:
Code:
=IF(ISNUMBER(FIND("&",A1,FIND("&",A1)+1)),IF(ISNUMBER(FIND(",",MID(A1,FIND("&",A1,FIND("&",A1)+1)+1,LEN(A1)))),TRIM(RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,"&","*",LEN(A1)-LEN(SUBSTITUTE(A1,"&","")))))),CONCATENATE(LEFT(A1,FIND(",",A1)-1),",",TRIM(MID(A1,FIND("&",A1,FIND("&",A1)+1)+1,LEN(A1))))),"")
 
Upvote 0
How about
Excel Workbook
AB
1HernaraMartin,Harry & Marie Anne & Ann SallyHernaraMartin,Ann Sally
2HernaraMartin,Harry & Marie Anne & Jenners,SallyJenners,Sally
3HernaraMartin,Harry & Marie Anne
Sheet1
Excel 2003
Cell Formulas
RangeFormula
B1=IF(LEN(A1)-LEN(SUBSTITUTE(A1,"&",""))=2,IF(ISNUMBER(SEARCH("*&*&*,",A1)),"",LEFT(A1,FIND(",",A1)))&TRIM(RIGHT(SUBSTITUTE(A1,"&",REPT(" ",255)),255)),"")
 
Last edited:
Upvote 0

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