Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Excel VB form to break apart a phone number?

Hey,

I am trying to figure out how to do the following...

Spreadsheet value is 555-111-2222

I've got 3 text boxes and I need that number broken down into each
text box...

Textbox1.value = 555
Textbox2.value = 111
Textbox3.value = 2222

I got textbox1 to work correctly using this code...

ThisTextbox = TextBox1.Value
charnum = InStr(1, ThisTextbox, "-")
If charnum < 0 Then
TextBox1.Value = Left(ThisTextbox, charnum - 1)
End If

But I can't figure out how to get it work with the rest of the
numbers... any ideas? I'm thinking LEN & LEFT can do it but I can't
figure out the context. Any help is greatly appreciated!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Excel VB form to break apart a phone number?

Something like this ?

Private Sub CommandButton1_Click()
Dim Parts() As String
Dim TelNum As String

Const SAMPLENUMBER As String = "555-111-2222"

On Error GoTo Handler

TelNum = SAMPLENUMBER

Parts = Split(TelNum, "-")
Textbox1.Text = Trim(Parts(0))
Textbox2.Text = Trim(Parts(1))
Textbox3.Text = Trim(Parts(2))

Exit Sub
Handler:

MsgBox "Telephone number <" & TelNum & " is not in the required format."

End Sub

NickHK

wrote in message
oups.com...
Hey,

I am trying to figure out how to do the following...

Spreadsheet value is 555-111-2222

I've got 3 text boxes and I need that number broken down into each
text box...

Textbox1.value = 555
Textbox2.value = 111
Textbox3.value = 2222

I got textbox1 to work correctly using this code...

ThisTextbox = TextBox1.Value
charnum = InStr(1, ThisTextbox, "-")
If charnum < 0 Then
TextBox1.Value = Left(ThisTextbox, charnum - 1)
End If

But I can't figure out how to get it work with the rest of the
numbers... any ideas? I'm thinking LEN & LEFT can do it but I can't
figure out the context. Any help is greatly appreciated!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Excel VB form to break apart a phone number?

On Feb 8, 2:44 am, "NickHK" wrote:
Something like this ?

Private Sub CommandButton1_Click()
Dim Parts() As String
Dim TelNum As String

Const SAMPLENUMBER As String = "555-111-2222"

On Error GoTo Handler

TelNum = SAMPLENUMBER

Parts = Split(TelNum, "-")
Textbox1.Text = Trim(Parts(0))
Textbox2.Text = Trim(Parts(1))
Textbox3.Text = Trim(Parts(2))

Exit Sub
Handler:

MsgBox "Telephone number <" & TelNum & " is not in the required format."

End Sub

NickHK

wrote in message

oups.com...



Hey,


I am trying to figure out how to do the following...


Spreadsheet value is 555-111-2222


I've got 3 text boxes and I need that number broken down into each
text box...


Textbox1.value = 555
Textbox2.value = 111
Textbox3.value = 2222


I got textbox1 to work correctly using this code...


ThisTextbox = TextBox1.Value
charnum = InStr(1, ThisTextbox, "-")
If charnum < 0 Then
TextBox1.Value = Left(ThisTextbox, charnum - 1)
End If


But I can't figure out how to get it work with the rest of the
numbers... any ideas? I'm thinking LEN & LEFT can do it but I can't
figure out the context. Any help is greatly appreciated!- Hide quoted text -


- Show quoted text -


Thanks Nick! It worked perfectly!

-Todd

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Excel VB form to break apart a phone number?

While Nick's solution works great and does just what you need, I have an
entire page on my web site that describes parsing out elements of a phone
number. It supports parsing out data for 7 different phone number formats.
See http://www.cpearson.com/excel/PhoneNum.htm for example code. You might
find it useful in the future if your encounter differently formatted phone
numbers.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)



wrote in message
oups.com...
On Feb 8, 2:44 am, "NickHK" wrote:
Something like this ?

Private Sub CommandButton1_Click()
Dim Parts() As String
Dim TelNum As String

Const SAMPLENUMBER As String = "555-111-2222"

On Error GoTo Handler

TelNum = SAMPLENUMBER

Parts = Split(TelNum, "-")
Textbox1.Text = Trim(Parts(0))
Textbox2.Text = Trim(Parts(1))
Textbox3.Text = Trim(Parts(2))

Exit Sub
Handler:

MsgBox "Telephone number <" & TelNum & " is not in the required format."

End Sub

NickHK

wrote in message

oups.com...



Hey,


I am trying to figure out how to do the following...


Spreadsheet value is 555-111-2222


I've got 3 text boxes and I need that number broken down into each
text box...


Textbox1.value = 555
Textbox2.value = 111
Textbox3.value = 2222


I got textbox1 to work correctly using this code...


ThisTextbox = TextBox1.Value
charnum = InStr(1, ThisTextbox, "-")
If charnum < 0 Then
TextBox1.Value = Left(ThisTextbox, charnum - 1)
End If


But I can't figure out how to get it work with the rest of the
numbers... any ideas? I'm thinking LEN & LEFT can do it but I can't
figure out the context. Any help is greatly appreciated!- Hide quoted
text -


- Show quoted text -


Thanks Nick! It worked perfectly!

-Todd



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Phone Number Excel 2003 Icehearted Excel Discussion (Misc queries) 6 September 30th 09 08:47 PM
How do I delete dashes from a phone number xxx-xxx-xxxx in Excel? ARADER Excel Worksheet Functions 3 February 16th 07 06:19 PM
How to format a phone number in Excel tfanatik Excel Discussion (Misc queries) 4 May 12th 06 04:53 PM
Keep phone number fomatting from excel to print on WORD labels Thelma Theiler Excel Discussion (Misc queries) 2 October 17th 05 01:47 AM
Alpha Phrase To Phone Number Calculator in excel alexp Excel Discussion (Misc queries) 1 February 3rd 05 03:23 PM


All times are GMT +1. The time now is 06:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"