vba - Excel sort order - special characters not first -


i use macro sort table data in 1 column:

activeworkbook.worksheets("sheet").sort.sortfields.add key:=range(sortrange), sorton:=xlsortonvalues, order:=xldescending, dataoption:=xlsortnormal 

is there way make code sort in order: first 0-9, a-z, , special characters (there @ least • , + last in sort order) ?

alright, sounded fun task, tried vityata's approach different lists in worksheet.

sub crazysort()  dim ws worksheet dim ws2 worksheet dim lastrow long dim yourcolumnindex, letters, numbers, others long dim long  set ws = worksheets("sheet") 'this sheet our temp lists, rename accordingly set ws2 = worksheets("tempsheet") columnscount = x = 1 letters = 1 others = 1 numbers = 1  ws j = 1 columnscount     'loop through cells in column     'change yourcolumnindex accordingly     while .cells(i, j) <> ""         'check ascii-code of first character in every list          select case asc(left(.cells(i, j), 1))             case 65 90, 97 122                 'if it's letter, put in column 1                 ws2.cells(letters, 1) = .cells(i, j)                 letters = letters + 1             case 48 57                 'if it's cipher, put in column 2                 ws2.cells(numbers, 2) = .cells(i, j)                 numbers = numbers + 1             case else                 'is else, put in column 3                 ws2.cells(others, 3) = .cells(i, j)                 others = others + 1         end select         = + 1     loop next end  end sub 

this part contains splitting list, here on out it's sorting , copy/pasting back.

have fun this.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -