+ Reply to Thread
Results 1 to 4 of 4

TextBox Error Handling issue

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-18-2009
    Location
    Chih, Mexico
    MS-Off Ver
    Excel 2010
    Posts
    102

    TextBox Error Handling issue

    HTML Code: 
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: TextBox Error Handling issue

    Private Sub TextBox1_Change()
        Dim lRow As Long
        Dim ws As Worksheet
        Set ws = Worksheets("Sheet1")
        
        If Len(Me.TextBox1.Value) > 6 Then
            MsgBox "Error!"
            Me.TextBox1.Value = Left(Me.TextBox1.Value, 6)
        End If
        
        lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
        
        If Len(Me.TextBox1.Value) < 6 Then
            Exit Sub
        End If
        
        With ws
            .Cells(lRow, 1).Value = Me.TextBox1.Text
            Me.TextBox1.Value = Left(Me.TextBox1.Value, 6)
            TextBox2.SetFocus
        End With
        
    End Sub
    
    Private Sub TextBox2_Change()
        Dim lRow As Long
        Dim ws As Worksheet
        Set ws = Worksheets("Sheet1")
        If Len(Me.TextBox2.Value) > 10 Then
            MsgBox "Error!"
            Me.TextBox2.Value = Left(Me.TextBox2.Value, 10)
        End If
        
        If Len(Me.TextBox2.Value) < 10 Then
            Exit Sub
        End If
        
        lRow = ws.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
        
        With ws
            .Cells(lRow, 2).Value = Me.TextBox2.Text
            Me.TextBox2.Value = Left(Me.TextBox2.Value, 10)
            TextBox1.SetFocus
        End With
    End Sub
    try this instead
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Forum Contributor
    Join Date
    08-18-2009
    Location
    Chih, Mexico
    MS-Off Ver
    Excel 2010
    Posts
    102

    Re: TextBox Error Handling issue

    Hi, humdingaling.
    Thanks for your help.
    I was having the same error with your code but i made a little modifications
    and i guess that now it's working, this how i end with the code.

    HTML Code: 

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: TextBox Error Handling issue

    not a problem
    i wasnt sure how exactly it was meant to be react but its good you know enough VBA to amend yourself

+ 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. Userform slow to enter data - event handling issue (I think)
    By baiken315 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-29-2016, 12:56 PM
  2. [SOLVED] Min value of array to textbox - Error issue
    By Lukael in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-19-2015, 05:11 PM
  3. Error handling inside error handling
    By grantastley in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-06-2015, 03:43 AM
  4. [SOLVED] Compile error with coding for date in textbox......2007 to 2010 issue!!!
    By Bflare in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-28-2014, 08:20 AM
  5. [SOLVED] Error Handling: Creating code to display error messages
    By Student1990 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-01-2013, 02:21 PM
  6. Error Handling - On Error GoTo doesn't trap error successfully
    By David in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2006, 02:10 PM
  7. Error handling with a handling routine
    By ben in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-15-2005, 11:06 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