How to solve this problem?

Vengeancez

New Member
Joined
Aug 19, 2011
Messages
9
Hi all,

I'm facing a problem in excel wish i couldn't find a solution or formula to it.

For says my data as listed below.

5487978 (7 numbers)
62481676 (8 numbers)
487-6214 (7 numbers)
9885462 (7 numbers)
63784659 (8 numbers)
8544064 (7 numbers)
541-2578 (7 numbers)

I want to add an additional of a number 6 to those data with 7 numbers only.

What formula can i use in excel to do this?

(please note that there are some - in those numbers, it may affect the formula)

Thanks for the help. :)
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
i've figure out already
If you are still looking for a formula solution, I am pretty sure this one works...

Code:
=SUBSTITUTE(LEFT(6,LEN(LEFT(A1,FIND("/",A1)-1))=8)&LEFT(A1,FIND("/",A1)-1)&"/"&LEFT(6,LEN(MID(A1,FIND("/",A1)+1,99))=8)&MID(A1,FIND("/",A1)+1,99),"-","")
 
Upvote 0
Now i am facing another issue.

How can i get the result for the b/m.

123-4567/123-4568 => 61234567/61234568
1234-5678/877-9854 => 12345678/68779854
Do these 'double-bungers' always have a "-" in the left part and the right part like these two examples or might there be cases like these for example?
12345678/123-4567
12345678/12345678

I've assumed a variety is possible.

For a formula solution, my suggestion is
=RIGHT(SUBSTITUTE(6&LEFT(A2,FIND("/",A2)-1),"-",""),8)&"/"&RIGHT(SUBSTITUTE(REPLACE(A2,1,FIND("/",A2),6),"-",""),8)


For a udf approach, I would avoid all the looping and use of WorksheetFunctions when suitable vba functions exist, since both those things will slow the code. CyFoo, you might like to investigate the vba
- 'Replace' function to use in place of the worksheetfunction 'Substitute', and
- 'InStr' function in place of the worksheetfunction 'Find'

<font face=Courier New><br><SPAN style="color:#00007F">Function</SPAN> FixIt(s <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>) <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> B<br>    <br>    B = Split(Replace(s, "-", ""), "/")<br>    B(0) = Right(6 & B(0), 8)<br>    B(1) = Right(6 & B(1), 8)<br>    FixIt = Join(B, "/")<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Function</SPAN><br></FONT>

Use in the worksheet like:
=FixIt(A2)
 
Upvote 0
@Peter: Thanks for sharing. Yeah, I noticed that the substitute() finds and replaces the old text with the new text without needing to loop, after I made that post. Thanks for pointing that out.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Do While InStr(1, text, "-") > 0
…<o:p></o:p>
s = WorksheetFunction.Find("/", text) <o:p></o:p>
Funny that I have used InStr in the loop but not in finding the position of the "/" :? Thanks for the tips too and I will take a look into the Replace(). I just thought it would be more familiar for Vengeancez to see Excel codes and know what just happened.<o:p></o:p>
<o:p></o:p>
CyFoo, you might like to investigate the vba
- 'Replace' function to use in place of the worksheetfunction 'Substitute', and
- 'InStr' function in place of the worksheetfunction 'Find'<o:p></o:p>
Is it because these are VBA functions instead of Excel functions? Will it be faster calling native VB functions in comparison to Excel functions? Kindly comment<o:p></o:p>
<o:p></o:p>
Great codes BTW :D both the methods. And Split() & Join() are the best<o:p></o:p>
<o:p></o:p>
Many thanks! Learn plenty this morning<o:p></o:p>
 
Last edited:
Upvote 0
Thanks for the formula, it works well.

Now i am facing another issue.

How can i get the result for the b/m.

123-4567/123-4568 => 61234567/61234568
1234-5678/877-9854 => 12345678/68779854

Try this:

Code:
=RIGHT("6"&SUBSTITUTE(LEFT(A1,FIND("/",A1)-1),"-",""),8)&"/"&RIGHT("6"&SUBSTITUTE(RIGHT(A1,LEN(A1)-FIND("/",A1)),"-",""),8)
 
Upvote 0
Is it because these are VBA functions instead of Excel functions? Will it be faster calling native VB functions in comparison to Excel functions?
Yes, generally significantly faster.
 
Upvote 0

Forum statistics

Threads
1,225,155
Messages
6,183,211
Members
453,151
Latest member
Lizamaison

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