Results 1 to 16 of 16

TextBox Change Event HELP

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,101

    TextBox Change Event HELP

    Hello Excel VBA experts,

    I have created a textbox (activex control) that I would like to work with my calculation. Notice that, the code below, I want users to enter only numerical numbers (including decimals...e.g. 25.50) and if it's really numerical, the textbox will show it in percentage format with 2 decimal places (e.g. 25.50%). However, whenever I try to type it more than 2 digits, it always goes to the 2nd IF statement where the msgbox is. The reason too why I want it to be a 'change' event so that I could see instantly of the calculation when the user input whatever numbers.

    Your help is greatly appreciated!

    Private Sub TextBox_MCDDisc_Change()
    
        With Me.TextBox_MCDDisc
            If Len(Me.TextBox_MCDDisc) = 0 Then
                .Value = vbNullString
            ElseIf Len(Me.TextBox_MCDDisc) >= 1 And Not IsNumeric(.Value) Then
                MsgBox "Sorry, only numbers allowed"
                .Value = vbNullString
            Else
                .Text = Format(.Value / 100, "0.00%")
                Range("A1").Value = TextBox_MCDDisc.Value
            End If
            
        End With
        
    End Sub
    Attached Files Attached Files
    Last edited by dluhut; 02-06-2013 at 03:10 PM. Reason: Attached file

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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