Extracting selections from multi-select listbox form

marcjasiq

New Member
Joined
May 1, 2018
Messages
3
Hello,

I've read several posts here and elsewhere trying to find a way to extract selected items from a multi-select listbox form into a column in a separate sheet but have had no luck thus far.

I have the aforementioned listbox (List Box 35 in Sheet 4) with around 100 or so values in it. I need to produce a column in Sheet 1 that populates any selected values from Sheet 4 - List Box 35.

Any help is greatly appreciated.

Thank you.
 
Here is some sample code

Using ""List Box 35" from Sheet 4, sending to Column A on Sheet 1.


Code:
Private Sub listBoxExtract()
    
    Dim Cnt As Long
    
    Dim outputSheet As Worksheet
    Set outputSheet = Sheets("Sheet1")
    
    Dim lbox As ListBox
    Set lbox = Sheets("Sheet4").Shapes("List Box 35").OLEFormat.Object
    
    Dim numSelected
    numSelected = 1
    
       For Cnt = 1 To lbox.ListCount - 1
          If lbox.Selected(Cnt) Then
		  
	     'May need to Modify The values in "Cells()" to designate destination
             outputSheet.Cells(numSelected, 1).value = lbox.List(Cnt)
			 
             numSelected = numSelected + 1
			 
          End If
       Next Cnt

End Sub
 
Upvote 0
Thank you!!! That worked. Is there anything additional to add in there in order for the extract in Sheet 1 to refresh if something is unselected? I assigned the macro to a button in Sheet 1 and upon clicking, it extracts all selections into Column A -- however, if I go back to my list box and unselect something, it will remain in my Column A export even upon re-clicking the macro-assigned button. New selections will get picked up, but something unselected is not removed.
 
Upvote 0
Actually I can just clear column A and click the Macro-assigned button to completely refresh the list which captures anything that was unselected.

My only other question is what if I have several list boxes and want List Box 35 in Column A, List Box 36 in Column B, etc?

Thank you again!
 
Upvote 0
Add this code to a module:

Code:
Sub listBoxExtract()
    
    Dim Cnt As Long
    
    Dim outputSheet As Worksheet
    Set outputSheet = Sheets("Sheet1")
    
    Dim ws As Worksheet
    Set ws = ActiveSheet
    
    Dim lbox As ListBox
    Set lbox = ws.Shapes(Application.Caller).OLEFormat.Object
    
    Dim numSelected As Long
    numSelected = 1
    
    Dim outCol As Long
    
    Select Case lbox.Name
    
        Case "List Box 35"
            outCol = 1
        
        Case "List Box 36"
            outCol = 2
        
    End Select
    
    outputSheet.Columns(outCol).ClearContents
    
       For Cnt = 1 To lbox.ListCount
          If lbox.Selected(Cnt) Then
          
         'May need to Modify The values in "Cells()" to designate destination
             outputSheet.Cells(numSelected, outCol).Value = lbox.List(Cnt)
             
             numSelected = numSelected + 1
             
          End If
       Next Cnt
       
End Sub

After you've added it, Right click any applicable ListBox and "Assign Macro..."

Select listBoxExtract, and then any time the list box updates, the changes will appear on Sheet 1.

I've designated 35 to go to the first column, and 36 to go to the second column. you can add/modify as needed.

Edit: "for" loop needed to run one more time (should be accurate now)
 
Last edited:
Upvote 0

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