Hello,
Can someone help me with a VBA code to restrict Textbox entry on a excel sheet to Numbers and special character(\) only. Whenever the user enters any Alphabet shuld receive an error message.
Hello,
Can someone help me with a VBA code to restrict Textbox entry on a excel sheet to Numbers and special character(\) only. Whenever the user enters any Alphabet shuld receive an error message.
Last edited by Biplab1985; 07-15-2015 at 02:06 PM.
Assuming an activex textbox
![]()
Private Sub TextBox1_Change() Dim objRegExp As Object, regExp_Matches As Object Set objRegExp = CreateObject("vbscript.regexp") objRegExp.Global = True objRegExp.Pattern = "[a-zA-Z]" Set regExp_Matches = objRegExp.Execute(TextBox1.Value) If regExp_Matches.Count <> 0 Then MsgBox ("No alpha characters allowed") Application.EnableEvents = False TextBox1.Text = "" Application.EnableEvents = True End If End Sub
Fantasctic. It worked fine but i also needed to restrict all special characters except "\".
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks