Work Number Field - show only phone numbers not extensions

bearcub

Well-known Member
Joined
May 18, 2005
Messages
734
Office Version
  1. 365
  2. 2013
  3. 2010
  4. 2007
Platform
  1. Windows
I need two separate pieces of information based upon the phone number field, the phone number itself and the extension in a separate field. I hope asking 2 questions in 1 is okay - I apologize in advance if this is against forum rules.

#1
I have a report where I 'm trying to show work numbers without extensions in one field and the phone extension (if they have one) in another field.

The phone number field has some fields with no phone number, some fields with this format "(###)###-####" and some field with this format "(###) ###-####"

When I use the left function below I get a "Type#" error in the all these fields.

Formula: Left([work_phone],14)

What formula show I use to get (650)333-5555 (165) or (650) 333-5555 (165) to display (650)333-5555 or (650) 333-5555 in the report and have the null fields show nothing?

#2

Also, I would like to extract the extension number, if there is one, in the field next to it. Using the same example I would like to display 165 in a separate field

Thank you in advance,

Michael
 
OK, if they are Text, and those are the only formats you can see, then we can use the InStrRev function to find the first space in the string when going from the right (end) to the left (start).
If the space is after the 10 character, then we know there is an extension.

So here are the two formulas:
Code:
PhoneNum: IIf(InStrRev([work_phone]," ")>10,Left([work_phone],InStrRev([work_phone]," ")-1),[work_phone])
Extension: IIf(InStrRev([work_phone]," ")>10,Mid([work_phone],InStrRev([work_phone]," ")+1),"")
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
thank you, I try this when I get back to the office,

so this formula will ignore fields that don't have a value in them (a null field)?

As always, thank you for your help,

Michael
 
Upvote 0
If you may have null entries, we will need to nest another level of checking. I just checked to see if the length of work_phone is greater than 0 like this:
Code:
PhoneNum: IIf(Len([work_phone])>0,IIf(InStrRev([work_phone]," ")>10,Left([work_phone],InStrRev([work_phone]," ")-1),[work_phone]),"")
Extension: IIf(Len([work_phone])>0,IIf(InStrRev([work_phone]," ")>10,Mid([work_phone],InStrRev([work_phone]," ")+1),""),"")
 
Last edited:
Upvote 0
thank you,

When I get to work within the next hour or so I'll apply these formulas. I'm sure they will do the trick. I didn't know about the Instr function being instrumental in this situation. Have to get used to Access formulas since I've been working in Excel exclusively for many years.

Michael
 
Upvote 0
Coupled with the InStr function in Access is the InStrRev function. This function is similar to InStr, but works backwards (starts search at the end of the string, looking back). It allows you to easily find the last instance of a character.
This function is awesome! I wish Excel had an equivalent to it.
 
Upvote 0
I noticed that last week. Some of the Excel functions could copy some of the Access functions I agree!
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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