I have a list of a 3000 items, I need to sort them by character length...
I cannot figure out how to do this in the normal auto sort functions...
Digging online I found some code like this that seems like it will do what I want:
But I cannot figure out how to get this to run... I have been reading about Macros, but cannot get this to work...![]()
Sub SortByLength() Dim lLoop As Long Dim lLoop2 As Long Dim str1 As String Dim str2 As String Dim MyArray Dim lLastRow As Long lLastRow = Range("A65536").End(xlUp).Row MyArray = Range(Cells(2, 1), Cells(lLastRow, 1)) 'Sort array For lLoop = 1 To UBound(MyArray) For lLoop2 = lLoop To UBound(MyArray) If Len(MyArray(lLoop2, 1)) < Len(MyArray(lLoop, 1)) Then str1 = MyArray(lLoop, 1) str2 = MyArray(lLoop2, 1) MyArray(lLoop, 1) = str2 MyArray(lLoop2, 1) = str1 End If Next lLoop2 Next lLoop 'Output sorted array Range("A2:A" & UBound(MyArray) + 1) = (MyArray) End Sub
please help![]()











LinkBack URL
About LinkBacks
Register To Reply

Bookmarks