Re: Listbox within Userform
Quote from rory;778990Add Kenneth's code to your Save button code:
Code Display MorePrivate Sub cbnEdit_Click() If Me.ListBox1.ListIndex = -1 Then MsgBox "You must select an item in the list first!" Exit Sub End If Dim lRow As Long lRow = GetSheetRow(GetAutoNumber) bEditing = 1 With mySheet .Cells(lRow, 2).Value = Me.TextBox1.Value .Cells(lRow, 3).Value = Me.TextBox2.Value .Cells(lRow, 4).Value = Me.TextBox8.Value .Cells(lRow, 5).Value = Me.TextBox9.Value .Cells(lRow, 6).Value = Me.TextBox3.Value .Cells(lRow, 7).Value = Me.ComboBox1.Value .Cells(lRow, 8).Value = Me.ComboBox2.Value .Cells(lRow, 9).Value = Me.TextBox18.Value .Cells(lRow, 10).Value = Me.TextBox27.Value .Cells(lRow, 11).Value = Me.TextBox30.Value .Cells(lRow, 12).Value = Me.TextBox31.Value .Cells(lRow, 13).Value = Me.TextBox32.Value .Cells(lRow, 14).Value = Me.TextBox22.Value .Cells(lRow, 15).Value = Me.TextBox17.Value .Cells(lRow, 16).Value = Me.TextBox20.Value .Cells(lRow, 17).Value = Me.TextBox28.Value .Cells(lRow, 18).Value = Me.TextBox15.Value .Cells(lRow, 19).Value = Me.TextBox33.Value .Cells(lRow, 20).Value = Me.TextBox7.Value .Cells(lRow, 21).Value = Me.ComboBox3.Value End With bEditing = 0 End Sub
Thank you so much, by inserting the code in the command button to save, it works as intended. I have a number of workbooks that uses this similar style and this has been very helpful.
Thank you!