ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   How do I sort multiple names within one cell? (https://www.excelbanter.com/excel-worksheet-functions/113691-how-do-i-sort-multiple-names-within-one-cell.html)

Deborah P. in Charlotte

How do I sort multiple names within one cell?
 
How do I sort multiple names, all within a single cell, with all names
sharing a single task listed in an adjacent cell? Thank you!

Don Guillett

How do I sort multiple names within one cell?
 
a bit, as in a LOT, more detail would be helpful.

--
Don Guillett
SalesAid Software

"Deborah P. in Charlotte" <Deborah P. in
wrote in message
...
How do I sort multiple names, all within a single cell, with all names
sharing a single task listed in an adjacent cell? Thank you!




Gord Dibben

How do I sort multiple names within one cell?
 
Deborah

Are the names delimited by comma? If so use the macro as is.

If separated by a space, make adjustments at marked points.

Sub SortCell()
Dim i As Long, j As Long
Dim swap1, swap2
Dim varr
varr = Split(ActiveCell, ",")
' varr = Split(Activecell, " ") if space delimited
' peform bubble sort
For i = 0 To UBound(varr) - 1
For j = i + 1 To UBound(varr)
varr(i) = Trim(varr(i))
varr(j) = Trim(varr(j))
If varr(i) varr(j) Then
swap1 = varr(i)
swap2 = varr(j)
varr(j) = swap1
varr(i) = swap2
End If
Next j
Next i
ActiveCell.Value = Application.Trim( _
Join(varr, ", "))
'remove the comma from between the ", "
End Sub


Gord Dibben MS Excel MVP


On Tue, 10 Oct 2006 10:16:03 -0700, Deborah P. in Charlotte <Deborah P. in
wrote:

How do I sort multiple names, all within a single cell, with all names
sharing a single task listed in an adjacent cell? Thank you!




All times are GMT +1. The time now is 07:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com