userform listbox assistance

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Greetings, below is a snippet of code from a userform that we have been using for a while. The form has a multitude of textboxes that the user enter data into, and then these textbox values get passed to a worksheet; pretty standard stuff and it works fine. They just asked me if I could change one of the textboxes to allow multiple entries, and they want to be able to add new items to the list. Not a problem I thought, I will just change the textbox to a listbox, reference a column on a separate worksheet so that it is easy for the users to add item to the listbox (using the rowsource property) and then when the user selects the items on the listbox those values gets passed back to the worksheet.

Everything works fine except the part about passing the selected values back to the worksheet; apparently it is not as easy as just swapping out the textbox for listbox. I have googled the heck out of this and have not been able to find what I am doing wrong, guessing that simply "highlighting" the items on the listbox is not in effect selecting any values. Is there a listbox parameter that I have not set correctly, or is there additional code that needs to be added to the listbox? Thank you for any advice - Rick



Code:
'   Transfer the Public Value
    Cells(NextRow, 9) = TextBox9.Text
    
'   Transfer the Operations Value
    Cells(NextRow, 10) = TextBox10.Text
    
'   Transfer the Technology Value
    Cells(NextRow, 11) = TextBox11.Text
    
'   Transfer the Controls Value
    Cells(NextRow, 12) = ListBox1.Value
    
'   Transfer the Recommendations
    Cells(NextRow, 13) = TextBox13.Text
    
'   Close UserForm5
    Unload UserForm5
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Assuming it's a multiselect listbox try
Code:
'    Transfer the Controls Value
    If ListBox1.ListIndex = -1 Then Exit Sub
    For i = 0 To ListBox1.ListCount - 1
         If ListBox1.Selected(i) = True Then
            Cells(NextRow, 12) = Cells(NextRow, 12) & "," & ListBox1.list(i)
         End If
    Next i
 
Upvote 0
Oh, okay - so you have to index the list - that makes sense, worked perfectly; I will add it to my coding book. Thank you for the tutoring Fluff, it is appreciated.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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