Forum

VBA Code to Remove ...
 
Notifications
Clear all

VBA Code to Remove ()s or -s from a UserForm Field

4 Posts
3 Users
0 Reactions
104 Views
(@pamela-simpsonchickasaw-net)
Posts: 20
Eminent Member
Topic starter
 

I have created a UserForm to insert data into a table.  One of the columns is for a phone number, so I have used the phone number special formatting on the worksheet to add in the parenthesis and dash.  Is there a way in the VBA code for my UserForm to remove any dashes or parenthesis a user may have added when they type in the phone number?  Currently on the UserForm I just have a text box to capture the information.

Thank you!

 
Posted : 16/08/2016 12:08 pm
(@catalinb)
Posts: 1937
Member Admin
 

You can try a fairly simple code that will prevent users from typing wrong values in real time. There are some examples on this page, with date formats and numeric values between a specific range, but the code can be easily adapted to any format you want. Here is a link: excel-user-form-assistant

Works for Mac also.

 
Posted : 16/08/2016 12:18 pm
(@pamela-simpsonchickasaw-net)
Posts: 20
Eminent Member
Topic starter
 

Thank you, that was helpful information. Cool

 
Posted : 16/08/2016 3:52 pm
(@sunnykow)
Posts: 1417
Noble Member
 

This is one I frequently use. It allows only numbers and nothing else (not even a space) to be entered into TextBox1.

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    'Allow only numbers to be entered
    Select Case KeyAscii
        Case Asc("0") To Asc("9")
        Case Else
            KeyAscii = 0
    End Select
End Sub

 
Posted : 16/08/2016 7:13 pm
Share: