Hello Everyone
I have a user data entry form with the listbox , I would like someone please help me with the VBA code to edit data directly from list box without any buttons. please see my code below. Thanks in advance
I have a user data entry form with the listbox , I would like someone please help me with the VBA code to edit data directly from list box without any buttons. please see my code below. Thanks in advance
Code:
Private Sub UserForm_Initialize() txtDate.Value = Format(Date, "mm/dd/yyyy")
End Sub
Code:
Private Sub CommandButton1_Click()
Dim LastRow As Long, ws As Worksheet
Set ws = Sheets("DataEntry")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
ws.Range("A" & LastRow).Value = txtDate.Text
ws.Range("B" & LastRow).Value = cboShift.Text
ws.Range("C" & LastRow).Value = cboDesc.Text
ws.Range("D" & LastRow).Value = txtAmount.Text
End Sub
Code:
Private Sub ListBox1_Click()
Dim i As Integer
i = Me.ListBox1.ListIndex
Me.ListBox1.Selected(i) = True
Me.txtDate.Value = Me.ListBox1.Column(0, i)
Me.cboShift.Value = Me.ListBox1.Column(1, i)
Me.cboDesc.Value = Me.ListBox1.Column(2, i)
Me.txtAmount.Value = Me.ListBox1.Column(3, i)
End Sub