Help to change Textbox value if Listbox item selected

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
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?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
You need to show the Userforms:- vbModeless
Like:-
Code:
Private Sub CommandButton1_Click()
UserForm1.Show vbModeless
End Sub
 
Upvote 0
Thank you, it is currently modeless, but the Listbox selected item bit is the part I am struggling with....
 
Upvote 0
This is Userform2.listbox1 sending to Userform1.textbox1
Code in Userform2 code module
Code:
Private [COLOR=navy]Sub[/COLOR] ListBox1_Click()
[COLOR=navy]Dim[/COLOR] n [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
[COLOR=navy]For[/COLOR] n = 0 To Me.ListBox1.ListCount - 1
[COLOR=navy]If[/COLOR] Me.ListBox1.Selected(n) [COLOR=navy]Then[/COLOR]
    UserForm1.TextBox1 = Me.ListBox1.List(n)
[COLOR=navy]End[/COLOR] If
[COLOR=navy]Next[/COLOR] n
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Upvote 0
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!!!
 
Upvote 0

Forum statistics

Threads
1,214,529
Messages
6,120,070
Members
448,943
Latest member
sharmarick

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top