+ Reply to Thread
Results 1 to 4 of 4

allow a Numeric only UserForm Textbox to start with a Decimal "."

Hybrid View

  1. #1
    Registered User
    Join Date
    04-16-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007, 2003
    Posts
    25

    allow a Numeric only UserForm Textbox to start with a Decimal "."

    i have the textboxes validated as numeric only so to enter anything less than 1 whole, you have to start off with 0.

    For example: instead of entering .5 you have to enter 0.5... I don't want to hear any complaints for the people using this form lol

    I have the following codes:
    1. This adds the value of each textbox as they change...
    Sub RealTime()
    txtEntry = Val(txt1) / 100 + Val(txt2) / 100 + Val(txt3) / 100 + Val(txt4) / 100 + Val(txt5) / 100 + Val(txt6) / 100 + Val(txt7) / 100 + Val(txt8) / 100 + Val(txt9) / 100 + Val(txt10) / 100
    End Sub

    2. This is just one of the 10 textboxes, when ever they are updated/changed they call in the realtime sub to update the sum of all the values (boxes 1 - 10).
    Private Sub txt1_Change()
    Call RealTime
    If txt1 <> vbNullString Then
    
        If Not IsNumeric(Me.txt1.Value) Then
          MsgBox "Please enter Numbers Only"
          txt1.SetFocus
        Else
         Call RealTime
        End If
    End If
    End Sub
    if i start off the entry with a decimal (.5) i get the error, but can continue entering, how can i get it to accept the decimal in the begining of the entry (.5), rather than having to type 0.5 ?

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    re: allow a Numeric only UserForm Textbox to start with a Decimal "."

    Hello DoriBeE,

    This change to your macro will allow a period as the first character.
    Private Sub TextBox1_Change()
     
      If txt1 <> vbNullString Then
    
        If Left(txt1, 1) = "." And Len(txt1.Text) = 1 Then Exit Sub
        
        If Not IsNumeric(txt1.Value) Then
          MsgBox "Please enter Numbers Only"
          txt1.Value = ""
          txt1.SetFocus
        Else
          Call RealTime
        End If
        
      End If
    
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    04-16-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007, 2003
    Posts
    25

    re: allow a Numeric only UserForm Textbox to start with a Decimal "."

    YOU ROCK!
    Gracias!


    It worked PERFECTLY ^_^!

  4. #4
    Registered User
    Join Date
    04-16-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007, 2003
    Posts
    25

    re: allow a Numeric only UserForm Textbox to start with a Decimal

    How do i mark this post as solved again!?
    Last edited by DoriBeE; 03-07-2011 at 12:29 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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