Book1 | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | N | O | P | AA | AB | |||||||||||||||||||||||||
1 | ||||||||||||||||||||||||||||||
2 | V58-1160 | V81-1314 | Play structure | Play structure, V58-1160, V81-1314 | ||||||||||||||||||||||||||
3 | ||||||||||||||||||||||||||||||
Hoja2 |
Sub SortCells()
Dim i As Integer, str As String, LR As Long
LR = Cells(Rows.Count, "N").End(xlUp).Row
For i = 1 To LR
str = WorksheetFunction.TextJoin(",", True, Range("N" & i & ":Z" & i))
Cells(i, 27) = str
Next
End Sub
Function SortWithinCell(CelltoSort As Range, DelimitingCharacter As String, IncludeSpaces As Boolean) As String
CelltoSortString = WorksheetFunction.Substitute(CelltoSort.Value, " ", "")
MyArray = Split(CelltoSortString, DelimitingCharacter)
For N = 0 To UBound(MyArray)
'For N = UBound(MyArray) To 0 Step -1
For M = 1 To UBound(MyArray)
'If MyArray(M) < MyArray(M - 1) Then
If MyArray(M) > MyArray(M - 1) Then
TempValue = MyArray(M)
MyArray(M) = MyArray(M - 1)
MyArray(M - 1) = TempValue
End If
Next M
Next N
For N = 0 To UBound(MyArray)
SortWithinCell = SortWithinCell & MyArray(N) & DelimitingCharacter
Next N
SortWithinCell = Left(SortWithinCell, Len(SortWithinCell) - 1)
If IncludeSpaces = True Then SortWithinCell = WorksheetFunction.Substitute(SortWithinCell, ",", ", ")
End Function
I used the following function to concatenate the data from N to Z (assumes you have Excel 365 because you need TEXTJOIN).
Code:Sub SortCells() Dim i As Integer, str As String, LR As Long LR = Cells(Rows.Count, "N").End(xlUp).Row For i = 1 To LR str = WorksheetFunction.TextJoin(",", True, Range("N" & i & ":Z" & i)) Cells(i, 27) = str Next End Sub
This put the concatenation in column AA
Then, in AB I used the following function (e.g., AB1 is =SortWithinCell(AA1,",", TRUE) and filled that down.)
Code:Function SortWithinCell(CelltoSort As Range, DelimitingCharacter As String, IncludeSpaces As Boolean) As String CelltoSortString = WorksheetFunction.Substitute(CelltoSort.Value, " ", "") MyArray = Split(CelltoSortString, DelimitingCharacter) For N = 0 To UBound(MyArray) 'For N = UBound(MyArray) To 0 Step -1 For M = 1 To UBound(MyArray) 'If MyArray(M) < MyArray(M - 1) Then If MyArray(M) > MyArray(M - 1) Then TempValue = MyArray(M) MyArray(M) = MyArray(M - 1) MyArray(M - 1) = TempValue End If Next M Next N For N = 0 To UBound(MyArray) SortWithinCell = SortWithinCell & MyArray(N) & DelimitingCharacter Next N SortWithinCell = Left(SortWithinCell, Len(SortWithinCell) - 1) If IncludeSpaces = True Then SortWithinCell = WorksheetFunction.Substitute(SortWithinCell, ",", ", ") End Function
Is that getting further along??
1. That isn't alphabetical as you originally requested. Can you clarify?I need it to look like this
VS8-1160 Essentials Play Structure, VS1-1314 Essentials Play Structure
That is working but I need it to look like this
VS8-1160 Essentials Play Structure, VS1-1314 Essentials Play Structure
Book1 | |||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | N | AA | |||||||||||||||||||||||||||
1 | SE-08 Jitterbug, FS74 Matrix (loose fill), VS8-1160 Essentials Play Structure, FS145 Twirler, 5299 T Nut | VS8-1160 Essentials Play Structure, SE Jitterbug, FS74 Matrix (loose fill), FS145 Twirler, 5299 T Nut | |||||||||||||||||||||||||||
Hoja23 |
Function RevSort(s As String) As String
Dim AL As Object
Dim vPart As Variant
Set AL = CreateObject("System.Collections.ArrayList")
For Each vPart In Split(Replace(s, ", ", ","), ",")
AL.Add vPart
Next vPart
AL.Sort
AL.Reverse
RevSort = Join(AL.ToArray, ", ")
End Function
Book1 | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
N | AA | |||||||||||||||
1 | SE-08 Jitterbug, FS74 Matrix (loose fill), VS8-1160 Essentials Play Structure, FS145 Twirler, 5299 T Nut | VS8-1160 Essentials Play Structure, SE-08 Jitterbug, FS74 Matrix (loose fill), FS145 Twirler, 5299 T Nut | ||||||||||||||
Sheet3 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
AA1 | AA1 | =RevSort(N1) |
Sub sort_data()
Dim arrList As Object, a As Variant, i As Long, ary As Variant
a = Range("N1", Range("N" & Rows.Count).End(xlUp)).Value
ReDim b(1 To UBound(a), 1 To 1)
For i = 1 To UBound(a)
Set arrList = CreateObject("System.Collections.ArrayList")
For Each ary In Split(a(i, 1), ",")
arrList.Add CStr(Trim(ary))
Next
arrList.Sort
arrList.Reverse
b(i, 1) = Join(arrList.ToArray, ", ")
Next
Range("AA1").Resize(UBound(a)).Value = b
End Sub