Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I need to figure out the code to concatenate multiple selections from
a list box into one cell with a comma as a divider. This is what I have pieced together from a few sources so far. I get an error when running this, so I know it doesn't work. Any help would be appreciated. Private Sub OK_exp_Click() Dim CellRange As Range Dim CellCnt As Integer Dim r As Integer Dim x As Range Dim w As String Dim y As Range Dim z As Range Dim sbuf As String w = ", " 'z = Range("Sheet2!A1") CellCnt = 0 For r = 0 To ListBox1.ListCount - 1 If ListBox1.Selected(r) Then CellCnt = CellCnt + 1 If CellCnt = 1 Then Set CellRange = ActiveSheet.UsedRange.Cells(r + 1) Else Set CellRange = Union(CellRange, ActiveSheet.UsedRange.Cells(r + 1)) End If End If Next r For Each y In CellRange If Len(y.Text) 0 Then sbuf = sbuf & y.Text & w Next z = Left(sbuf, Len(sbuf) - 1) ActiveCell.Value = z Unload Me End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
userform listbox cannot get listbox.value to transfer back to main sub | Excel Programming | |||
VBA: Creating listbox similar to the one in Pivot table (Listbox+Checkbox) | Excel Programming | |||
I know how to concatenate ,can one de-concatenate to split date? | New Users to Excel | |||
listbox.value not equal to listbox.list(listbox.listindex,0) | Excel Programming | |||
Is refreshing listbox rowsource in listbox click event possible? | Excel Programming |