• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Type in Textbox Save in sheet based ListBox Row

marreco

Member
Hi.
how save data in TexBox1 into sheet("Plan1"), based seletec row in listBox?
Code:
Private Sub CommandButton1_Click()
    'how save data in TexBox1 into sheet("Plan1"), based seletec row in listBox?
End Sub

Private Sub ListBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    With ListBox2
        If .ListIndex > -1 Then
            UserForm1.TextBox1.Text = .List(.ListIndex, 3)
        End If
    End With
End Sub

Private Sub UserForm_Initialize()
    With ListBox1
        .List = Sheets("Plan1").Cells(1, 1).CurrentRegion.Value
        .ColumnCount = Sheets("Plan1").Cells(1, 1).CurrentRegion.Columns.Count
        .ColumnWidths = "40;50;50;50"
    End With

    With ListBox2
        .List = Sheets("Plan2").Cells(1, 1).CurrentRegion.Value
        .ColumnCount = Sheets("Plan2").Cells(1, 1).CurrentRegion.Columns.Count
        .ColumnWidths = "50;40;50;50"
    End With
End Sub
 

Attachments

  • ListBoxEditSheet.jpg
    ListBoxEditSheet.jpg
    127 KB · Views: 12
I'd suggest uploading workbook not just image. As it will allow us to test code quickly.

Just looking at your image. My suggestion is to obtain listindex # of selected item in ListBox2 (add 1 if you have header set in listbox) to determine the row#.
From the looks of it, column number is fixed to 4.
 
Something like this.

Code:
Private Sub CommandButton1_Click()
  Sheets("Plan2").Cells(Me.ListBox2.ListIndex + 1, 4) = Me.TextBox1.Value
End Sub

This assumes order of listbox2 contains exactly same info as Plan2 sheet.
 
Back
Top