excel - Sort rows by a specific column containing numbers -


how sort rows column containing numbers in ascending or descending order? know how sort using filters , using sort function in vba. sorts in alphabetical order not numbers.

this far have done.but still sorting coming alphabetically.

sub sortdata() dim lastrow integer  noofrows = sheets("rawdata").range("a" & rows.count).end(xlup).row sheets("rawdata").rows("2:" & noofrows).numberformat = "0"     sheets("rawdata").sort.sortfields.add key:=range("a1"), _         sorton:=xlsortonvalues, order:=xlascending, dataoption:=xlsortnormal     activeworkbook.sheets("rawdata").sort         .setrange range("a1:b" & noofrows)         .header = xlyes         .matchcase = false         .orientation = xltoptobottom         .sortmethod = xlpinyin         .apply     end  end sub 

i prefer range.sort method:

[edit 2]: have added .texttocolumns line programmatically address numbers stored text issue

sub sortdata()      dim ws worksheet      set ws = sheets("rawdata")      ws.range("a1:b" & ws.cells(rows.count, "a").end(xlup).row)         intersect(.cells, ws.columns("a")).texttocolumns         .sort intersect(.cells, ws.columns("a")), xlascending, header:=xlguess     end  end sub 

[edit]: after reading asker's comment:

i provide example . if column contains values:1,2,55,12,14,5343,22222,9 after sorting using filter or inbuilt sort method. values sorted follows:1,12,14,2,22222,5343,9. need result follows: 1,2,9,12,14,5334,22222. there in-built function this?

the problem numbers stored text. you'll need convert them numbers.

select column -> data -> text columns -> finish

now numbers should sort correctly.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -