+ Reply to Thread
Results 1 to 3 of 3

Restrict textbox entry

Hybrid View

Biplab1985 Restrict textbox entry 07-15-2015, 01:56 PM
stnkynts Re: Restrict textbox entry 07-15-2015, 02:14 PM
Biplab1985 Re: Restrict textbox entry 07-15-2015, 02:39 PM
  1. #1
    Forum Contributor
    Join Date
    05-19-2015
    Location
    Karnataka, INdia
    MS-Off Ver
    MS Office 2010
    Posts
    277

    Restrict textbox entry

    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.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Restrict textbox entry

    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

  3. #3
    Forum Contributor
    Join Date
    05-19-2015
    Location
    Karnataka, INdia
    MS-Off Ver
    MS Office 2010
    Posts
    277

    Re: Restrict textbox entry

    Fantasctic. It worked fine but i also needed to restrict all special characters except "\".

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Restrict the value entered into a textbox on a userform
    By D.Lovell in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-11-2015, 05:30 PM
  2. [SOLVED] Restrict Userform Textbox to Numbers Only
    By Mousiefuzz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-09-2015, 04:24 AM
  3. [SOLVED] How to restrict textbox input with module?
    By alee001 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-26-2014, 04:16 AM
  4. Restrict textbox entries to numbers
    By domnisignis18 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-11-2013, 03:48 AM
  5. restrict textbox on userform to mm/yyyy
    By lcoreilly in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-22-2010, 11:40 AM
  6. Restrict text entry in textbox to JUST TEXT
    By TheNewGuy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-24-2009, 03:54 PM
  7. Restrict Textbox entry
    By pauluk in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-15-2007, 08:08 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1