Textbox Question

will2learn

Board Regular
Joined
Dec 1, 2005
Messages
144
I have a userform with various textboxes on it, which inturn feeds the data into a spreadsheet. One of the boxes is used to record messages/notes and is causing a problem as the users sometimes enter data with a ",".

Is there away in which I can stop the user entering a "," as they are typing?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Will2learn,

what about something like this,

Private Sub TextBox1_Change()
If TextBox1.Text = "," Then
MsgBox "please dont do that"
TextBox1 = Null
End If
End Sub


or if not this then something along these lines.

Haratio
 
Upvote 0
Your suggestion works if only "," is entered in the text box. I need it to throw up an error if something like this is entered "hello, everyone". As the user enters the "," I need away to stop them entering the ",".
 
Upvote 0
Why do you need to prevent the user entering a comma?
 
Upvote 0
Code:
Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 188 Then
TextBox1.Text = Left(TextBox1.Text, Len(TextBox1.Text) - 1)
End If
End Sub

This isn't a fantastic way of doing it..... but it works. And 1 real drawback is that if a user holds the ',' key down then it won't work properly.... but who's going to do that?

I'll try to come up with a better method for you that updates faster. Or you could just go ahead and parse the strings before moving them.

Chad
 
Upvote 0
Chad,

Thanks for your code That seems to have done the trick. I've added a warning message so that the user knows not to use the comma.
 
Upvote 0
Hi,

This will cater for the event that the user pastes in text with a comma:
Code:
Private Sub TextBox1_Change()
If InStr(TextBox1.Text, ",") <> 0 Then
    With Application
        .EnableEvents = False
        TextBox1.Text = Replace(TextBox1.Text, ",", " ")
        .EnableEvents = True
    End With
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,635
Messages
6,120,660
Members
448,975
Latest member
sweeberry

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