Oh boy, the fun part
=IF((ISNUMBER(--MID(A1,FIND("-",A1)-1,1))*ISNUMBER(--MID(A1,FIND("-",A1)+1,1))+NOT(ISNUMBER(--MID(A1,FIND("-",A1)-1,1)))*NOT(ISNUMBER(--MID(A1,FIND("-",A1)+1,1)))),A1,SUBSTITUTE(A1,"-","",1))
OK lets break it down:-
This thing really breaks into two main pieces of formula, and is just a great big IF statement:-
=IF(Condition TRUE, This, That) ==>
=IF(Condition TRUE,A1,SUBSTITUTE(A1,"-","",1))
Condition TRUE evaluation =
(ISNUMBER(--MID(A1,FIND("-",A1)-1,1))*ISNUMBER(--MID(A1,FIND("-",A1)+1,1))+NOT(ISNUMBER(--MID(A1,FIND("-",A1)-1,1)))*NOT(ISNUMBER(--MID(A1,FIND("-",A1)+1,1))))
Main gist of that ISNUMBER stuff is to see if we can get a 1 (Equates to TRUE in Excel) in the argument for the IF function. This is done by interrogating the characters eithers ide of the '-' to see if they match in context, eg both numeric or both text. If they do then the formula returns a 1, and if they don't then it's a 0.
First thing to do no matter what is to find where the '-' is in the string, hence the FIND("-",A1), and this will return a number such as 2,3,4,5,6,7,8 etc depending on the position within the string.
Next we need to take a look at the character either side of that '-', so hence the two MID statements:-
MID(A1,FIND("-",A1)-1,1) and
MID(A1,FIND("-",A1)+1,1)
Note the -1 and the +1. within the MID function these point you to the character before and after the '-'. The MID function without the +1 or -1 eg MID(A1,FIND("-",A1),1) effectively says take a look at the string in A1 and give me the character at the position specified by the result of the FIND statement. The +1 and -1 then add or subtract a 1 from the result of that FIND function and take you either side of that character.
Now, the result of a MID function is a always text, so we need to try and coerce the result to numeric if we can, hence the -- before each of the statements. This means that the first evaluation of each side of the '-' to see if it is numeric will give you either
1*1 = 1
1*0 = 0
0*1 = 0
0*0 = 0
Only the first combination can possibly result in a 1. We then do the opposite because it may be that neither of them are numeric, so hence the NOT(ISNUMBER bit, and once again we end up with the following possible combinations:-
1*1 = 1
1*0 = 0
0*1 = 0
0*0 = 0
The formula then procedes to apply both the above tests to the data and then add the results'
Now, it can never be the case that both are numeric and both are text, so you can never get a 2, ie if the data are both numeric then the first part of the formula gives you 1*1 whereas the second part gives you 0*0, and 1*1 + 0*0 gives you 1. Opposite if both were text ie if the data are both text then the first part of the formula gives you 0*0 whereas the second part gives you 1*1, and 0*0 + 1*1 gives you 1.
This value of 1 or 0 then gets fed through to the argument required for the IF function and then based on it being 1 or 0, ie TRUE or FALSE it then decides to give you one of the options eg with or without dashes.
Bit rambly but hopefully it gives you the gist
Regards
Ken...............
----------------------------------------------------------------------------
![[peace] [peace] [peace]](/data/assets/smilies/peace.gif)
It's easier to beg forgiveness than ask permission
----------------------------------------------------------------------------