Click Event in UserForm's Listbox doesn't work

Panosmpo

New Member
Joined
Nov 19, 2022
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
I want to pass values from a userform to an excel table. I use an UPDATE button but it only works when i doubleclick on items of the listbox. When i use one click it doesn't work! Any ideas why?Thanks a lot in advance...

---- code for click event in listbox-------

Private Sub ListBox1_Click()
Me.TextBox11.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 0)
Me.ComboBox1.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 1)
Me.TextBox1.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 2)
Me.TextBox2.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 3)
Me.ComboBox2.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 4)
Me.TextBox3.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 13)
Me.TextBox6.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 24)
Me.TextBox4.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 18)
Me.ComboBox3.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 19)
Me.TextBox7.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 20)
Me.ComboBox4.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 21)
Me.ComboBox5.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 25)
Me.ComboBox6.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 26)
Me.TextBox12.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 0)
End Sub

------- code for update-------
* textbox11 is the id number of the row

Private Sub Update_Click()
If Me.TextBox11.Value = "" Then
MsgBox "Error."
Exit Sub
End If

Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("ÄÕÍÁÌÏËÏÃÉÏ")
Dim selected_row As Long
selected_row = Application.WorksheetFunction.Match(CLng(Me.TextBox11.Value), sh.Range("A:A"), 0)

sh.Range("B" & selected_row).Value = Me.ComboBox1.Value
sh.Range("C" & selected_row).Value = Me.TextBox1.Value
sh.Range("D" & selected_row).Value = Me.TextBox2.Value
sh.Range("O" & selected_row).Value = Me.TextBox3.Value

Me.ComboBox1.Value = ""
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""

Call Refresh_Data
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,958
Latest member
Hat4Life

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