Consulting

Results 1 to 3 of 3

Thread: Edit Listbox Items

  1. #1
    Banned VBAX Regular
    Joined
    Aug 2010
    Posts
    54
    Location

    Edit Listbox Items

    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-q...box-items.html

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    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?

  3. #3
    Banned VBAX Regular
    Joined
    Aug 2010
    Posts
    54
    Location
    Typo error on my part Mike - thanks for your suggestion, works great!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •