Consulting

Results 1 to 3 of 3

Thread: Userform: Creating default text in a Textbox from the text entered in another Textbox

  1. #1
    VBAX Regular
    Joined
    May 2015
    Posts
    44
    Location

    Userform: Creating default text in a Textbox from the text entered in another Textbox

    Hi all,

    I'm creating a Word UserForm to populate a document.

    In the form there is one section that has 3 TextBoxes. Textbox 1 relates to the first year, Textbox2 the second year and Textbox3 the third year. Quite often the value that will be entered into Textbox 1 will be the same that user will then enter into Textbox 2 and Textbox 3. However this will not always be the case.

    What I want to do is - Fill Textbox 2 and Textbox 3 with the text that is inputted into Textbox1 - but so that this can be deleted/retyped with a different text in the event that the user decides the values will be different for 2 and 3.

    Any thoughts would be great!

    Cheers,
    AJHEZ

  2. #2
    The following code should so the trick

    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
        If Me.TextBox2.Text = "" Then
            Me.TextBox2.Text = Me.TextBox1.Text
        End If
        If Me.TextBox3.Text = "" Then
            Me.TextBox3.Text = Me.TextBox1.Text
        End If
    End Sub
    This will fill textboxes 2 and 3 on exit from textbox1 if they don't already have a value.
    You may change 2 and 3 without effecting a change elsewhere.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    May 2015
    Posts
    44
    Location
    A king amongst men!

    Fantastic as always. Thanks so much.

    All the best,
    AJHEZ

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •