Change Data with List Box

maabbas

Board Regular
Joined
Aug 11, 2011
Messages
201
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

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
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top