Make empty spaces in phone numbers in TextBox using Excel VBA.

Masta

New Member
Joined
Feb 22, 2022
Messages
33
Office Version
  1. 2021
  2. 2019
  3. 2016
Platform
  1. Windows
1660757285582.png

When i enter first number of phone in TextBox1 i need that phone to show up in TextBox2 with spaces. That is the same one with TextBox3.
I tryed everything but i have problem when i do that in cell i have good result but when i try to get that 064 23 77 890 from cell to TextBox i got result 0642377890 and that is not what i need. I dont have slighest clue how to acomplish this. I think the only solution is to skip cells and all do with VBA code. Please help me.
 

Attachments

  • 1660756913343.png
    1660756913343.png
    6 KB · Views: 5

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi Masta,

how about
VBA Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With TextBox1
  If Len(.Value) > 0 Then
    TextBox2.Value = Format(.Value, "000 00 00 0##")
  End If
End With
End Sub
if you leave TextBox1.

Ciao,
Holger
 
Upvote 0
Hi Masta,

how about
VBA Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With TextBox1
  If Len(.Value) > 0 Then
    TextBox2.Value = Format(.Value, "000 00 00 0##")
  End If
End With
End Sub
if you leave TextBox1.

Ciao,
Holger
Thank you on fast response! I will try this now.
 
Upvote 0
Hi Masta,

how about
VBA Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With TextBox1
  If Len(.Value) > 0 Then
    TextBox2.Value = Format(.Value, "000 00 00 0##")
  End If
End With
End Sub
if you leave TextBox1.

Ciao,
Holger
Is it possible to have 2 different value in this TextBox1 sollution, i have 2 different lenght in numbers 0641231231 and 064123123, and this need to look like this 064 12 31 231 and 064 123 123 ?
 
Upvote 0
Hi Masta,

maybe
VBA Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With TextBox1
  If Len(.Value) > 0 Then
    Select Case Len(.Value)
      Case 10
        TextBox2.Value = Format(.Value, "000 00 00 000")
      Case 9
        TextBox2.Value = Format(.Value, "000 000 000")
      Case Else
        TextBox2.Value = "Number must show either 9 or 10 digits"
  End Select
  End If
End With
End Sub
Ciao,
Hoilger
 
Upvote 0
Solution

Forum statistics

Threads
1,214,914
Messages
6,122,211
Members
449,074
Latest member
cancansova

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