How to display a phone number in 3 TextBoxes?

underpressure

Board Regular
Joined
Nov 24, 2012
Messages
141
My UserFormDataEntry uses 3 TextBoxes to add the phone number to the cell as ##########

My worksheet displays the formatted phone numbers as (###) ###-####

How do I extract the numbers from the worksheet cell into another UserForm with 3 Textboxes?
This doesn’t work:
Code:
Me.TextBox4.Value = Mid(Cells(x, "D").Value, 1, 3)
Me.TextBox5.Value = Mid(Cells(x, "D").Value, 4, 3)
Me.TextBox6.Value = Right(Cells(x, "D").Value, 4,)

And, I'm looking for a similar solution for DateOfBirth in Cells(x, “H”) which is formatted ##/##/##.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
.
This will generate the data correctly :

Code:
Me.TextBox1.Value = Left(Cells(i, "D").Value, 3)
Me.TextBox2.Value = Mid(Cells(i, "D").Value, 5, 3)
Me.TextBox3.Value = Right(Cells(i, "D").Value, 4)
 
Upvote 0
Thanks for the code...
But, I still get blank TextBoxes.
All the other cells/textboxes work fine...like names, addresses, etc.
 
Upvote 0
.
I suspect there is more code in your project than you have posted. Perhaps something like :

Code:
Sub viewPhoneNumbers()
Dim i As Integer

For i = 1 To 20

Me.TextBox1.Value = Left(Cells(i, "D").Value, 3)
Me.TextBox2.Value = Mid(Cells(i, "D").Value, 5, 3)
Me.TextBox3.Value = Right(Cells(i, "D").Value, 4)

i = i + 1

Next i


End Sub

If your code is something close to the above, the code is running through all the rows of data located in rows #1 to row #20 , then it stops. There is now opportunity for the code to display a single phone number at a time.

If you were to utilize a macro like the following, attached to a command button, the phone numbers would be displayed one at a time for each press of the button :

Code:
Sub phonenums()


Selection.Offset(1, 0).Select
    
    Me.TextBox1.Value = Left(ActiveCell.Value, 3)
    Me.TextBox2.Value = Mid(ActiveCell.Value, 5, 3)
    Me.TextBox3.Value = Right(ActiveCell.Value, 4)
   


End Sub

You have indicated your other data displays correctly. What code are you using for that (names, addresses, etc) ? You should follow the same pattern.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

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