Patriot2879
Well-known Member
- Joined
- Feb 1, 2018
- Messages
- 1,259
- Office Version
- 2010
- Platform
- Windows
Hi Good morning, hope you can help please, i have a Userform6 where data is entered, then i have an update button called 'Commandbutton4', where once clicked i want it to transfer the data from Userform6 into the ListBox1 which is in Userform1.
I have tried the code below but it is not working, i hope you can help me please.
This below is the code for my Listbox1
I have tried the code below but it is not working, i hope you can help me please.
VBA Code:
Private Sub CommandButton4_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("In Day VL")
Dim row_number As Long
Dim max_id As Long
max_id = Application.WorksheetFunction.Max(sh.Range("A:A"))
If Me.TextBox2.Value = "" Then ''' Insert
row_number = Application.WorksheetFunction.CountA(sh.Range("A:A")) + 1
sh.Range("A" & row_number).Value = max_id + 1
Else '''' Update
row_number = Application.WorksheetFunction.Match(Int(Me.TextBox2.Value), sh.Range("A:A"), 0)
End If
sh.Range("B" & row_number).Value = Me.TextBox10.Value
sh.Range("C" & row_number).Value = Me.ComboBox2.Value
sh.Range("D" & row_number).Value = Me.TextBox11.Value
sh.Range("E" & row_number).Value = Me.TextBox3.Value
sh.Range("F" & row_number).Value = Me.ComboBox3.Value
sh.Range("K" & row_number).Value = Now
Call Reset_Form
MsgBox "Done", vbInformation
Call Refresh_Listbox
End Sub
This below is the code for my Listbox1
Code:
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Me. Textbox2.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 0)
Me. Textbox10.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 1)
Me.ComboBox2.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 2)
Me. Textbox11.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 3)
Me. Textbox3.Value = Format(Me.ListBox1.List(Me.ListBox1.ListIndex, 4), "D-MMM-YYYY")
If Me.ListBox1.List(Me.ListBox1.ListIndex, 5) <> "" Then
Me.txt_Close_Date.Value = Format(Me.ListBox1.List(Me.ListBox1.ListIndex, 5), "D-MMM-YYYY")
End If
Me. ComboBox3.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 6)
End Sub