Results 1 to 4 of 4

Excel Userform TextBox - Change partial string in textbox with command button

Threaded View

  1. #1
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Excel Userform TextBox - Change partial string in textbox with command button

    Hello, I am trying to find a way to replace part of a string in a textbox. I have the user enter a job number and I have it verify they have entered the side they are working on which is just 2 choices "-TOP" or "-BOTTOM". So when they work on the same job number, I would like to replace one for the other. If they have this: "98-1002-600-TOP" and are finished, I want to press the button and replace just the -TOP with -BOTTOM. Also work in the opposite way if they start BOTTOM first, then it will change to -TOP. Any ideas on this? Your help is greatly appreciated.

    Here is the code I have for checking the end of the job number.... Now I just need to know how to replace one for the other when I change jobs.

    'check for -top / -btm entry in field
    Private Sub txtCCA_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    
     With Me.txtCCA
            If Len(.Value) Then
                If CheckIt(.Value) Then
                    MsgBox "*Enter -TOP or -BTM *", vbInformation, .Value
                    Cancel = True
                End If
            End If
        End With
    End Sub
    
    'check for -top / -btm entry
    Private Function CheckIt(ByVal txt As String) As Boolean
        With CreateObject("VBScript.RegExp")
            .Pattern = "\d*(-TOP|-BTM)\d*"
            .ignorecase = True
            CheckIt = Not .test(txt)
        End With
    End Function
    Last edited by Nu2Java; 05-05-2012 at 09:02 PM.

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