PDA

View Full Version : Solved: Listbox, should be simple!



panmat
01-18-2012, 01:02 PM
Any help would be welcome.
I have a userform with one listbox populated with a named range (Names).
also on the form are 2 textboxes for the user to input 2 numbers.
When the user clicks OK button the selected listbox name should be looked up against the named range on the worksheet and the 2 textbox values written to the next 2 adjacent columns.
Thanks Pete

mdmackillop
01-18-2012, 01:22 PM
Private Sub ListBox1_Click()
Dim r As Range
Dim i As Long
i = ListBox1.ListIndex + 1
Set r = Range(ListBox1.RowSource)
r.Cells(i, 1).Offset(, 1) = TextBox1
r.Cells(i, 1).Offset(, 2) = TextBox2
End Sub

panmat
01-19-2012, 07:21 AM
Thanks for your time, just what I wanted
Pete

mdmackillop
01-19-2012, 09:18 AM
Glad to help.
You can mark you threads solved using the Thread Tools dropdown