LEFT() for each rows in a single cell?

jeffcoleky

Active Member
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:

DanteAmor

Well-known Member
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.
 

Fluff

MrExcel MVP, Moderator
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 :LOL:
 
Last edited:

jeffcoleky

Active Member
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.
 

Fluff

MrExcel MVP, Moderator
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.
 

jeffcoleky

Active Member
So no easy formula method in excel either? If not, thanks everyone for making it work this way! it saves me hours.
 

mohadin

Active Member
Hi
What about
Code:
B1=LEFT(A1,LEN(A1)-LEN(RIGHT(A1,LEN(MID(A1,FIND("<",A1),255))))-1)
 
Last edited:

Some videos you may like

This Week's Hot Topics

  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • find many based on a certain criteria
    good evening, I hope someone can help me? I have a workbook sheet 2 contains lots of data.... I would like to be able to find anything on sheet...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
  • Text Format
    I have a sheet for user to keyin the data. The format of the data can be 451 / 1903, 0012 / 9908 or 00287 / 0099. The number after the "/" is...
  • Macro to copy values across rows and transposing them and add the user id
    [FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]Hi,[/COLOR][/SIZE][/FONT] [FONT=Times New...
Top