+ Reply to Thread
Results 1 to 7 of 7

Check if the last part of entered string is an Integer

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-23-2013
    Location
    Bangalore
    MS-Off Ver
    2010
    Posts
    130

    Check if the last part of entered string is an Integer

    Hi All,

    I have a macro with a Textbox and a button.

    in that macro user is allowed write any values. But I need to put a restriction that user must enter only alpha numeric value and also the last part should be numeric.

    Like if the user enters TEST_100 then it is correct.. but if the user enters 100_TEST then it show an error message..

    So only last part of the string should be numeric..

    can anyone help me?

    Thanks.

  2. #2
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: Check if the last part of entered string is an Integer

    try this
    Private Sub CommandButton1_Click()
        With CreateObject("vbscript.regexp")
            .Global = True
            .Pattern = "[A-Z]+\_[0-9]+"
        If .test(TextBox1.Value) Then
            MsgBox "Correct Entry"
        Else
            MsgBox "Wrong Entry"
        End If
        End With
    End Sub
    Give Feedback and Click(*)

  3. #3
    Forum Contributor
    Join Date
    02-23-2013
    Location
    Bangalore
    MS-Off Ver
    2010
    Posts
    130

    Re: Check if the last part of entered string is an Integer

    Thanks Venkat.. working as expected..

  4. #4
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: Check if the last part of entered string is an Integer

    glad i could help, and thank you for the feedback.

  5. #5
    Forum Contributor
    Join Date
    02-23-2013
    Location
    Bangalore
    MS-Off Ver
    2010
    Posts
    130

    Re: Check if the last part of entered string is an Integer

    Hi Venkat,..

    Could you help me to change few things in the above regex?

    liek I have changed it as below

     With CreateObject("vbscript.regexp")
            .Global = True
            .Pattern = "[A-Za-z]+\_[0-9]+"
        If .test(TextBox2.Value) Then
    so now I am able to use both caps and small letters in the first field..

    Example: Test_100 and TEST_100, test_100 holds good..

    I want to have another logic which should allow users to enter test100 or TEST100 or Test100.. What I mean to say that, it should allow only _ in the text box but that should not mandatory... and no other special characters are allowed which is now working fine.. Pls Help..

    Thanks.

  6. #6
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: Check if the last part of entered string is an Integer

    Private Sub CommandButton1_Click()
        With CreateObject("vbscript.regexp")
            .Global = True
            .Pattern = "[A-z]+\_?[0-9]+"
        If .test(TextBox1.Value) Then
            MsgBox "Correct Entry"
        Else
            MsgBox "Wrong Entry: You are Only Allowed to Entry as Examples: TEST_100, test_100, TEST100, test100, Test100"
        End If
        End With
    End Sub

  7. #7
    Forum Contributor
    Join Date
    02-23-2013
    Location
    Bangalore
    MS-Off Ver
    2010
    Posts
    130

    Re: Check if the last part of entered string is an Integer

    Hi Venkat..

    it is allowing other special characters as well.. like if i use test\_test100 it allows.. but i want it to allow only _ and which should not be mandatory..

    Thanks

+ 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. Can I use a defined integer as part of a shape name
    By newatmacros in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-23-2010, 05:12 PM
  2. Check that input in textbox is an integer
    By marcusr in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-26-2007, 01:01 PM
  3. [SOLVED] Check if a value is an integer using VBA code
    By Rayo K in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-03-2006, 04:45 PM
  4. [SOLVED] how do I convert an integer to hh:mm (part II)
    By kdell in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2006, 05:40 PM
  5. [SOLVED] how do I test for Integer?:check out ROUND
    By DerbyJim1978 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-06-2005, 06:05 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