List Values to TextBox
I used this code to show the second userform2:
Me.Hide
UserForm2.Show
Me.Show
Then I used this code behind UserForm2:
Option Explicit
Private Sub CommandButton1_Click()
With Me.ListBox1
If .ListIndex < 0 Then
'nothing selected, same as cancel?
Else
UserForm1.TextBox1.Value = .List(.ListIndex, 0)
UserForm1.TextBox2.Value = .List(.ListIndex, 1)
UserForm1.TextBox3.Value = .List(.ListIndex, 2)
End If
End With
Unload Me
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim myRng As Range
With Worksheets("sheet1")
Set myRng = .Range("a1:G5")
End With
With Me.ListBox1
.List = myRng.Value
.ColumnCount = myRng.Columns.Count
.MultiSelect = fmMultiSelectSingle
End With
With Me.CommandButton1
.Default = True
.Caption = "Ok"
End With
With Me.CommandButton2
.Cancel = True
.Caption = "Cancel"
End With
End Sub
"Patrick C. Simonds" wrote:
Have a UserForm with a number of TextBoxes. When I click on TextBox1 it
opens a new Userform which displays a ListBox What I need to know is when I
close the ListBox Userform, how do I get the selected values (which are in
Column 1,5 and 6) into TextBox 1, 2 and 3.
--
Dave Peterson
|