Results 1 to 2 of 2

Thread: [RESOLVED] VBA UserForm : Two Textbox selection with One Click

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2019
    Posts
    37

    Resolved [RESOLVED] VBA UserForm : Two Textbox selection with One Click

    I have 2 buttons in my form. So when i press on Button1 , value "A" will come in textbox2 & textbox3 and when i press Button2 "B" will come in textbox2 & textbox3.
    User can enter how much ever values to the textbox2 & textbox3 which will append to the last.
    And also user can click on the textbox2 anywhere user wants , and can enter the values using button click event . ( I am using textbox2.Seltext instead of textbox2.text) .

    Issue i am facing :

    User pressed button1 2 times : Values in textbox2 and textbox3 will be " A A ".
    Now the User pressed in between "A A" in the textbox. and then pressed button 2.
    Values in textbox1 will be "A B A" while in textbox3 will be " A A B" . But i want the values in textbox3 same as textbox2 "A B A" .

    Code:
    Private Sub Button1_Click()
    If TextBox2.SelText = "" Then
    TextBox2.SelText = " A "
    TextBox3.SelText = " A "
    Else
    TextBox2.SelText = TextBox2.SelText + " A "
    TextBox3.SelText = TextBox3.SelText + " A "
    End If
    End Sub
    Code:
    Private Sub Button2_Click()
    If TextBox2.SelText = "" Then
    TextBox2.SelText = " B "
    TextBox3.SelText = " B "
    Else
    TextBox2.SelText = TextBox2.SelText + " B "
    TextBox3.SelText = TextBox3.SelText + " B "
    End If
    End Sub

  2. #2

    Thread Starter
    Member
    Join Date
    Jun 2019
    Posts
    37

    Re: VBA UserForm : Two Textbox selection with One Click

    I got the idea. Thanks

    Code:
    textbox1.selstart = textbox2.selstart

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
  •  



Click Here to Expand Forum to Full Width