List Values to TextBox

  • Thread starter Patrick C. Simonds
  • Start date
P

Patrick C. Simonds

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.
 
D

Dave Peterson

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
 
D

Dave Peterson

In the textboxes?

if isnumeric(.list(.listindex,0) then
UserForm1.TextBox1.Value = format(.List(.ListIndex, 0), "00:00")
end if

(or "hh:mm" or "mm:ss"????)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top