Results 1 to 8 of 8

Thread: Help to change Textbox value if Listbox item selected
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular sharky12345's Avatar
    Join Date
    Aug 2010
    Posts
    3,235
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Help to change Textbox value if Listbox item selected

    Listbox1 is on a Userform which is displayed in addition to another Userform. Can I change the value of a Textbox on the 2nd Userform if an item is selected in the Listbox in the 1st? So for example, Listbox 1 has items 1, 2, 3, 4 and 5 - if I select '2' I want Textbox2 on the 2nd Userform to display that value. Anyone?
    There isn't a day go by without me learning something new about VBA!

  2. #2
    MrExcel MVP
    Join Date
    Jan 2008
    Posts
    14,837
    Post Thanks / Like
    Mentioned
    26 Post(s)
    Tagged
    12 Thread(s)

    Default Re: Help to change Textbox value if Listbox item selected

    You need to show the Userforms:- vbModeless
    Like:-
    Code:
    Private Sub CommandButton1_Click()
    UserForm1.Show vbModeless
    End Sub

  3. #3
    Board Regular sharky12345's Avatar
    Join Date
    Aug 2010
    Posts
    3,235
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Help to change Textbox value if Listbox item selected

    Thank you, it is currently modeless, but the Listbox selected item bit is the part I am struggling with....
    There isn't a day go by without me learning something new about VBA!

  4. #4
    MrExcel MVP
    Join Date
    Jan 2008
    Posts
    14,837
    Post Thanks / Like
    Mentioned
    26 Post(s)
    Tagged
    12 Thread(s)

    Default Re: Help to change Textbox value if Listbox item selected

    This is Userform2.listbox1 sending to Userform1.textbox1
    Code in Userform2 code module
    Code:
    Private Sub ListBox1_Click()
    Dim n As Long
    For n = 0 To Me.ListBox1.ListCount - 1
    If Me.ListBox1.Selected(n) Then
        UserForm1.TextBox1 = Me.ListBox1.List(n)
    End If
    Next n
    End Sub
    Regards Mick

  5. #5
    Board Regular sharky12345's Avatar
    Join Date
    Aug 2010
    Posts
    3,235
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Help to change Textbox value if Listbox item selected

    Thanks Mick, just what I need.
    There isn't a day go by without me learning something new about VBA!

  6. #6
    MrExcel MVP
    Join Date
    Jan 2008
    Posts
    14,837
    Post Thanks / Like
    Mentioned
    26 Post(s)
    Tagged
    12 Thread(s)

    Default Re: Help to change Textbox value if Listbox item selected

    You're welcome
    Regrds Mick

  7. #7
    New Member
    Join Date
    Sep 2012
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Help to change Textbox value if Listbox item selected

    Hello,
    What if 3 columns value in listbox need to shown in 3 differnt textbox in usrform

  8. #8
    New Member
    Join Date
    Aug 2019
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Help to change Textbox value if Listbox item selected

    How could it be the other way, please?
    I'm trying imput back listbox2 form combined text with separating "; " in listbox1

    Private Sub Listbox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    Load userform2
    With Userform2

    Dim s As String
    Dim txtStrg As String
    Dim WArray() As String

    txtStrg = Me.Listbox1.List(Listbox1.ListIndex, 7)
    WArray() = Split(txtStrg, "; ")

    For i = LBound(WArray) To UBound(WArray)
    For x = 0 To Userform2.Listbox2.ListCount - 1

    If Me.Listbox1.List(Listbox1.ListIndex, 7) <> "" Then

    Userform2.Listbox2.Selected (x)
    Else
    .Listbox2.Value = Me.Listbox1.List(Listbox1.ListIndex, 7)
    End If

    Next x
    Next i
    .Show


    End With

    End Sub

    Please help!!!

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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