Putting data into ListBox1 from UserForm6 to Userform1 listbox

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. 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.

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
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I have tried the code below
I see no references in your code to UserForm1, nor code that appears to put data into a ListBox in that form. In fact none of your code puts data into any ListBox. Perhaps you need to show us sub Refresh_Listbox.
but it is not working
What are you expecting to happen, what part of the code do you think does that, and what actually happens instead?
 
Upvote 0
I see no references in your code to UserForm1, nor code that appears to put data into a ListBox in that form. In fact none of your code puts data into any ListBox. Perhaps you need to show us sub Refresh_Listbox.

What are you expecting to happen, what part of the code do you think does that, and what actually happens instead?
HI Good morning thank you for your reply, the commandbutton4 vba code is for the userform, the command button is located in the userform. i didnt realise i hjad to name the userform in the code if the command button was placed in the userform. Sorry about that if you can help me with that please that would be great, as i am completely stuck on it.
 
Upvote 0
That wasn't my point. There is no code in your post that would do anything to any listbox.
i want it to transfer the data from Userform6 into the ListBox1

I have tried the code below
Exactly which code do you think is going to do that?
 
Upvote 0
That wasn't my point. There is no code in your post that would do anything to any listbox.

Exactly which code do you think is going to do that?
Hi I thought it would be my command button code that would list it in the list box
 
Upvote 0
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.

Hi,

Guessing that you have one userform that submits data to a worksheet and now you are trying to create another to edit the data? then if this is the case, it’s unlikely that you would need another userform to do this – you should be able to perform both actions from the same userform.

Rather than keep posting snippets of your code asking forum to assist with different issues, I suggest that you share copy of your workbook with dummy data on a file sharing site like dropbox & provide a link to it.

Perhaps then someone here may take up the challenge to help you resolve the issues you are having developing your project.



Dave
 
Upvote 1

Forum statistics

Threads
1,224,812
Messages
6,181,096
Members
453,021
Latest member
Justyna P

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