Assistance with Formulae - different scenarios

shellp

Board Regular
Joined
Jul 7, 2010
Messages
194
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
Hello

I have some text in a report that comes across a certain way, some with the same doctor formatted differently, and I want to create a formula to handle each scenario. I have 4 scenarios and I am having issues including all 4 scenarios in the same formula/column. Just to check that the syntax per condition was correct, I formatted 4 columns and added a different formula per column to ensure that each format was addressed and it was. But when I combine them altogether, it doesn't work. The final format should be Smith, Paul W for the scenarios below:

VBA Code:
‘format where the word Dr. is included in the name
‘example Smith, Dr. Paul W
=IF(AND(ISERROR(FIND("(",M2,1)),FIND("DR.",M2,1)>0),TRIM(CONCATENATE(MID(M2,1,FIND(",",M2,1)-1),",",MID(M2,FIND("DR.",M2,1)+3,LEN(M2)))))

‘format where there is a bracket for the physician’s city but Dr. not also included in the name
‘example Smith, Paul W (Toronto)
=IF(AND(ISERROR(FIND("Dr.",M2,1)),FIND("(",M2,1)>0),TRIM(CONCATENATE(MID(M2,1,FIND(",",M2,1)-1),",",MID(M2,FIND(",",M2,1)+1,FIND("(",M2,1)-FIND(",",M2,1)-1))))

‘format where there is a bracket for the physician’s city AND Dr. also included in the name
‘example Smith, Dr. Paul W (Toronto)
=IF(AND(FIND("(",M2,1)>0,FIND("DR.",M2,1)>0),TRIM(CONCATENATE(MID(M2,1,FIND(",",M2,1)-1),",",MID(M2,FIND(".",M2,1)+1,FIND("(",M2,1)-FIND(".",M2,1)-1)))

‘format where there is no bracket and no Dr. included in the name
‘example Smith, Paul W
=IF(AND(ISERROR(FIND("(",M2,1)),ISERROR(FIND("DR.",M2,1))),M2)

The error I get when combining all is either #Value! for all cells or where the criteria worked in one of the 4 columns, it doesn't work when combined. Any and all assistance greatly appreciated, thanks.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I wouldn't even attempt to join them together, based on your examples, try

=TRIM(LEFT(SUBSTITUTE(SUBSTITUTE(A2,"Dr.",""),"(",REPT(" ",LEN(A2))),LEN(A2)))
 
Upvote 0
Solution
Jasonb75, you are brilliant!! Thank you so much, this worked amazingly!!
 
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,309
Members
449,080
Latest member
jmsotelo

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