LEFT() for each rows in a single cell?

jeffcoleky

Active Member
Joined
May 24, 2011
Messages
274
The following data is in a SINGLE cell. I'm trying to get the phone number from each line and output it as just a list of phone numbers in a single cell.

FROM THIS:
Code:
[TABLE="width: 357"]
<tbody>[TR]
[TD](734) 435-8519 < Sent TXT 14/25/09 @ 08:54
(734) 917-1416 < Sent TXT 14/25/09 @ 08:54
(734) 742-6437 < Sent TXT 14/25/09 @ 08:54
(734) 435-8511 < Sent TXT 14/25/09 @ 08:54-Bob's number
(734) 360-5106 < Sent TXT 14/25/09 @ 08:54
(734) 880-3306 < Sent TXT 14/25/09 @ 08:54
(734) 384-0869 < Sent TXT 14/25/09 @ 08:54-Not working
(734) 494-5151 < Sent TXT 14/25/09 @ 08:54
(435) 851-8519 < Sent TXT 14/25/09 @ 08:54-Yelled at me
(734) 408-2349 < Sent TXT 14/25/09 @ 08:54
(734) 224-7269 < Sent TXT 14/25/09 @ 08:54
(734) 299-4730 < Sent TXT 14/25/09 @ 09:02
(734) 299-4703 < Sent TXT 14/25/09 @ 09:02-Not working#
(734) 291-9930 < Sent TXT 14/25/09 @ 09:02
(734) 345-8002 < Sent TXT 14/25/09 @ 09:02[/TD]
[/TR]
</tbody>[/TABLE]

TO THIS:
Code:
[TABLE="width: 357"]
<tbody>[TR]
[TD="class: xl65, width: 357"](734)  435-8519
(734) 917-1416
(734) 742-6437
(734) 435-8511
(734) 360-5106
(734) 880-3306
(734) 384-0869
(734) 494-5151
(435) 851-8519
(734) 408-2349
(734) 224-7269
(734) 299-4730
(734) 299-4703
(734) 291-9930
(734) 345-8002[/TD]
[/TR]
[TR]
[TD="class: xl65, width: 357"][/TD]
[/TR]
</tbody>[/TABLE]

I'm not sure how to use LEFT() for this type of situation. The text located to the right of the numbers could be ANYTHING. But the phone number format is always the same.

Any ideas?
 
Last edited:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try whit this UDF

<table border="1" cellspacing="0" style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:565.54px;" /><col style="width:307.01px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td >A</td><td >B</td></tr><tr style="height:93px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >2</td><td >(734) 435-8519 < Sent TXT 14/25/09 @ 08:54<br />(734) 917-1416 < Sent TXT 14/25/09 @ 08:54<br />(734) 742-6437 < Sent TXT 14/25/09 @ 08:54<br />(734) 435-8511 < Sent TXT 14/25/09 @ 08:54-Bob's number<br />(734) 360-5106 < Sent TXT 14/25/09 @ 08:54</td><td >(734) 435-8519<br />(734) 917-1416<br />(734) 742-6437<br />(734) 435-8511<br />(734) 360-5106</td></tr></table><br /><table style="font-family:Arial; font-size:10pt; border-style: groove ;border-color:#00ff00;background-color:#fffcf9; color:#000000; "><tr><td ><b></b></td></tr><tr><td ><table border = "1" cellspacing="0" cellpadding="2" style="font-family:Arial; font-size:9pt;"><tr style="background-color:#cacaca; font-size:10pt;"><td >Cell</td><td >UDF Formula</td></tr><tr><td >B2</td><td >=getphonenumber(A2)</td></tr></table></td></tr></table>

Code:
Function getphonenumber(cad As String)
  Dim c As Variant, newcad As String
  For Each c In Split(cad, Chr(10))
    newcad = newcad & Left(c, 14) & Chr(10)
  Next
  getphonenumber = Left(newcad, Len(newcad) - 1)
End Function

-------------------
HOW TO INSTALL UDFs

If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use TextOnly just like it was a built-in Excel function.
 
Upvote 0
Maybe
Code:
Function jeffcoleky(Cl As Range) As String
    Dim Sp As Variant
    Dim i As Long
    
    Sp = Split(Cl, Chr(10))
    For i = 0 To UBound(Sp) - 1
        jeffcoleky = jeffcoleky & Split(Sp(i), "<")(0) & vbLf
    Next i
    jeffcoleky = jeffcoleky & Split(Sp(i), "<")(0)
End Function
Used in the worksheet like
=jeffcoleky(a2)

EDIT:
I'm obviously way too slow today :laugh:
 
Last edited:
Upvote 0
OK those all do work in excel so thank you! However, just like Fluff, I'm a little slow.

Is there a way to use a FORMULA for this? Or could these be adapted to work in google sheets? If not, I'll make what you've posted work since this IS an Excel forum I posted in! lol.
 
Upvote 0
I certainly don't know of any simple formula that would do it, and I've never used GoggleSheets so can't convert the VBA to the version of Java that it uses.
 
Upvote 0
So no easy formula method in excel either? If not, thanks everyone for making it work this way! it saves me hours.
 
Upvote 0
Hi
What about
Code:
B1=LEFT(A1,LEN(A1)-LEN(RIGHT(A1,LEN(MID(A1,FIND("<",A1),255))))-1)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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