Multi select ListBox

mdo8105

Board Regular
Joined
Nov 13, 2015
Messages
83
Hi,

I was able to return multiple values into one cell; however, I am trying to figure out how to change my delimiter from"," to Char(10):

Code:
 For i = 0 To DEPListBox.ListCount - 1            If DEPListBox.Selected(i) Then     'If selected is True
                strTemp = strTemp & DEPListBox.List(i) & ","      'Edit ", " to required separators
            End If
        Next i
        
        If Len(strTemp) > 2 Then    'The variable will always be greater than 2 if any selections in the listbox
            strTemp = Left(strTemp, Len(strTemp) - 2) 'remove last comma and space (Edit 2 to length of separators)
        End If
        
ThisWorkbook.Worksheets("TST_SHEET").Cells(dcc + 1, 10).Value = strTemp

Thank you
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Replace a comma with char 10 in variable myString like this:

Code:
myString = Replace(myString, ",", Chr(10))
 
Last edited:
Upvote 0
Hi,

I was able to return multiple values into one cell; however, I am trying to figure out how to change my delimiter from"," to Char(10):

Code:
 For i = 0 To DEPListBox.ListCount - 1            If DEPListBox.Selected(i) Then     'If selected is True
                strTemp = strTemp & DEPListBox.List(i) [B][COLOR="#FF0000"]& vbLf[/COLOR][/B]      'Edit ", " to required separators
            End If
        Next i
        
        If Len(strTemp) > 2 Then    'The variable will always be greater than 2 if any selections in the listbox
            strTemp = Left(strTemp, Len(strTemp) - [B][COLOR="#FF0000"]1[/COLOR][/B]) 'remove last comma and space (Edit 2 to length of separators)
        End If
        
ThisWorkbook.Worksheets("TST_SHEET").Cells(dcc + 1, 10).Value = strTemp
See the changes in red above... note that vbLf is a built-in constant for the Line Feed character which is also Chr(10) in VBA, not CHAR(10) as that is an Excel worksheet function name.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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