Format Textbox for phone number

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
On my userform I have Textbox9 which will hold a phone number.

I currently populate my user form with values from my worksheet.

On my worksheet I see phone numbers like so 07899 327122

I populate the Textbox9 but the leading 0 is missing thus me only seeing 7899 327122

Please advise what code I need to use so the full number is shown with its 0

Thanks.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Does the cell actually contain the leading 0 or is it just formatted that way? And how are you populating the control from the cell?
 
Upvote 0
When I type the number I actually type the 0

I populate the userform Textbox like this.

VBA Code:
Me.TextBox9.Value = Cells(ActiveCell.Row, 18).Value
 
Upvote 0
Then the cell does not actually contain the leading 0. What is the number format of the cell?
 
Upvote 0
You could use (supposing your phone numbers are stored as numbers):
VBA Code:
UserForm1.Textbox9.Value = Format(Range("A2").Value, "00000 000000")
If your phone numbers are stored as strings, then:
VBA Code:
UserForm1.Textbox9.Value = Format(Val(Range("A2").Value), "00000 000000")
 
Upvote 0
Just checked it again.
Userform Textbox I type the phone number with a leading 0

I send userform values to worksheet & phone number is the same as what I had typed on userform.

I then populate values from worksheet to another userform & the 0 is then missing.

The column on the worksheet where the phone number is located is column W so it’s 23
 
Upvote 0
You could use (supposing your phone numbers are stored as numbers):
VBA Code:
UserForm1.Textbox9.Value = Format(Range("A2").Value, "00000 000000")
If your phone numbers are stored as strings, then:
VBA Code:
UserForm1.Textbox9.Value = Format(Val(Range("A2").Value), "00000 000000")
Dont see why you meantion A2
 
Upvote 0
A2 is my favourite cell. You didn't give any specifics about where the data resided in your worksheet, so I had to pick a cell for my example. So - A2.
 
Upvote 0
I’m above message I mentioned column W is that what you are looking for ?
 
Upvote 0
My time zone is ahead of yours. So posts that I make seem to happen after posts that you make later. If someone in, say, UTC+8, had 8 hours deducted from their post time, and someone in, for example, UTC-5, had 5 hours added to their post time, then the posts would be in the correct order.

When I replied to you, the ONLY post was your original one, which had no details. Taking into account your later posts:
VBA Code:
UserForm1.Textbox9.Value = Format(Cells(ActiveCell.Row, 18).Value, "00000 000000")
 
Upvote 0
Solution

Forum statistics

Threads
1,215,101
Messages
6,123,095
Members
449,095
Latest member
gwguy

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