PDA

View Full Version : [SOLVED] Edit Listbox Items



sharky12345
08-12-2013, 09:06 AM
I'm using the following to select and edit items within a Userform Listbox;
Private Sub CommandButton2_Click()

Dim rCell As Range
With ListBox2
Set rCell = Range(.RowSource).Offset(.ListIndex).Resize(1)
rCell.Value = TextBox1.Value
End With
End Sub
Private Sub ListBox1_Click()

TextBox1.Value = ListBox2.Value
End Sub

I'd like to know please if it is possible to amend the code so that the item it selects and edits is ONLY the one in the 3rd column, I want the values in columns 1 and 2 to remain.

Posted elsewhere too: http://www.mrexcel.com/forum/excel-questions/719695-edit-listbox-items.html

mikerickson
08-12-2013, 11:00 AM
Try

Private Sub ListBox1_Click()
With ListBox2
If .ListIndex = 0 Then
TextBox1.Value = vbNullString
Else
TextBox1.Value = .List(.ListIndex, 2)
End If
End With
End Sub

Is there a reason that that code is in the Click event for ListBox1 rather than ListBox2?

sharky12345
08-12-2013, 11:27 AM
Typo error on my part Mike - thanks for your suggestion, works great!