Listbox Multiselect

Cyril Beki

Board Regular
Joined
Sep 18, 2021
Messages
57
Office Version
  1. 2016
Platform
  1. Windows
Hello expert,

I have 2 Listboxs (txtActionby & Listbox1), i would like to do a multiselect in txtActionby separated by comma and will be displayed in the Listbox1 once the Add button is pressed.
And whenever i want to update the data, the previous multiselected person separated by comma will be highlighted in the txtActionby. How can i do that ? i Appreaciate all your help. Thanks in advance

Download the file here:
Multiselect.PNG
 
It still doesnt show up the separated data sir. Still blank
View attachment 47204nk
For your information: The data inside txtActionby is depend upon the combobox (txtSection). You need to choose first then it will show up the data to be picked inside txtActionby
Example: Choose diffusion from Combobox (txtSection), then it will show the data to be picked inside txtActionby
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Back in post #2, I said:

Assign strActionBy to the appropriate column of ListBox1.

Are you doing this? I can't recommend a code without knowing the listbox structure just looking at an image as there may be columns with 0 width.

After strActionBy is formed inside add button code (right after "Next i") you have to assign it to the ListBox1's appropriate column.
 
Upvote 0
Back in post #2, I said:



Are you doing this? I can't recommend a code without knowing the listbox structure just looking at an image as there may be columns with 0 width.

After strActionBy is formed inside add button code (right after "Next i") you have to assign it to the ListBox1's appropriate column.
hg.PNG

Is this what you mean sir ?
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Listbox Multiselect
and Listbox Multiselect

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
How do you assign the values for other columns? "Tube1" for example? It is the same, just the column number (index) has to be for ActionTakenBy.

Please copy paste code when you do, and use the VBA tag rather than inserting an image to the code.

1631972562651.png


The assignment on your last post, suggests that strActionBy should be equal to the selected ListBox1 row's column 10. You want to do the opposite to enter a value there.

However, since you are adding a new row, should look something like this:

VBA Code:
ListBox1.List (ListBox1.ListCount - 1, 10) = strActionBy
 
Upvote 0
How do you assign the values for other columns? "Tube1" for example? It is the same, just the column number (index) has to be for ActionTakenBy.

Please copy paste code when you do, and use the VBA tag rather than inserting an image to the code.

View attachment 47206

The assignment on your last post, suggests that strActionBy should be equal to the selected ListBox1 row's column 10. You want to do the opposite to enter a value there.

However, since you are adding a new row, should look something like this:

VBA Code:
ListBox1.List (ListBox1.ListCount - 1, 10) = strActionBy
VBA Code:
Dim i As Long
Dim strActionBy As String

strActionBy = ""

For i = 0 To txtActionby.ListCount - 1
    If txtActionby.Selected(i) Then strActionBy = strActionBy & ", "    ' There is a space after comma for readability
Next i
ListBox1.List(ListBox1.ListCount - 1, 10) = strActionBy

is this how you suggest me to write sir ? and for Tube 1, it's dependant combobox. The combobox for tube 1 (example) is from this code
VBA Code:
Private Sub txtMachine_Change()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Combobox")

Dim o As Integer

Me.txtTube.Clear
For o = 2 To sh.Range("A" & Application.Rows.count).End(xlUp).row
If sh.Range("A" & o).value = "Module" Then
    If sh.Range("C" & o) = Me.txtMachine.value Then
        Me.txtTube.AddItem sh.Range("B" & o)
    End If
End If
Next o
End Sub
 
Upvote 0
I mean when you add a new row to ListBox1, how do you do it? Complete code for the "Add" button.

Edit: I downloaded your workbook, but get repetitive errors on open, and then only choice was disable macros. I will check again.
 
Upvote 0
Just noticed you don't qualify the Range object, best is to reference the worksheet as well. i.e., Worksheets("<name_here>").Range(...)... Now, this would not be very efficient, and we usually create a worksheet object and set it to the worksheet and use that as a reference, so the code is much more readable and easier to write.

VBA Code:
' Declare the variable
Dim ws as Worksheet

' Set the object
Set ws = Worksheets("<name_here")

' Use the variable
ws.Range(...)... = ...

' Clean up set variable
Set ws = Nothing

Back to the topic: So you are using this part to populate ListBox1.

VBA Code:
With Range("A9:P" & lr)
    Me.ListBox1.RowSource = .Address
End With

Therefore you must change the cell value within that range that correspond to ActionTakenBy for this row.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
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