How to ignore a hyphen within a cell

Doggerry

New Member
Joined
Aug 20, 2007
Messages
40
Office Version
  1. 365
Platform
  1. Windows
Hi

I wonder if anyone could give me a bit of advice on a formula please.

I am using the formula below to ensure that certain surnames have a space between them, however it is also adding a space after the hyphen in double barrelled surnames.

I am trying to put a space between Van and Kempen.

The formula I am using is - =REPLACE(B2, 1+MIN(FIND(CHAR(64+COLUMN($B$2:$Z$2)),MID(B2,2,255)&(CHAR(64+COLUMN($B$2:$Z$2))))), 0, " ")

1644264457252.png


Thank you in anticipation.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
How about
Excel Formula:
=IF(ISERROR(FIND("-",B2)),REPLACE(B2, 1+MIN(FIND(CHAR(64+COLUMN($B$2:$Z$2)),MID(B2,2,255)&(CHAR(64+COLUMN($B$2:$Z$2))))), 0, " "),B2)
 
Upvote 0
Presuming your formula works as intended you could wrap a SUBSTITUTE formula around it:

=SUBSTITUTE(REPLACE(B2,1+MIN(FIND(CHAR(64+COLUMN($B$2:$Z$2)),MID(B2,2,255)&(CHAR(64+COLUMN($B$2:$Z$2))))),0," "),"- ","-")
 
Upvote 0
Hi Fluff and Steve the Fish.

Thank you very much for your help, both work but will not pick up one name that is DeAsis, it should be De Asis. I have been trying to figure it out but with no joy. Any ideas?

Thanks.
 
Upvote 0
It's because char(66) is B so you are missing As. Change the $B$ to $A$ in both column functions.
 
Upvote 0
I will be able to sleep tonight now
I hope that you do not have nightmares about names like these.

22 02 08.xlsm
ABCD
1FNAMESNAMEOUTPUT (Fluff)OUTPUT (stf)
2JaneMcDonaldMc DonaldMc Donald
3BasilD'OliveraD' OliveraD' Olivera
Sample
Cell Formulas
RangeFormula
C2:C3C2=IF(ISERROR(FIND("-",B2)),REPLACE(B2, 1+MIN(FIND(CHAR(64+COLUMN($A$2:$Z$2)),MID(B2,2,255)&(CHAR(64+COLUMN($A$2:$Z$2))))), 0, " "),B2)
D2:D3D2=SUBSTITUTE(REPLACE(B2,1+MIN(FIND(CHAR(64+COLUMN($A$2:$Z$2)),MID(B2,2,255)&(CHAR(64+COLUMN($A$2:$Z$2))))),0," "),"- ","-")


BTW, 'Mark as solution' is meant to mark the post that best suits you as the answer to your question. I have therefore removed the mark from post #6 as it does not meet that criteria. :)

I also suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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