excel - Sorting multiple sheets - code clean up -


looking guidance on sorting columns across multiple sheets.

i have 2 data sets (tab1: abc , tab2: xyz). i'm trying sort both sheets (range column column j) column in descending order.

this have far... recorded. clean code , better ways approach sorting columns. help/tips appreciated.

sub sortingcolumns()  application.goto reference:="abc!a1" activeworkbook.worksheets("abc").sort.sortfields.clear activeworkbook.worksheets("abc").sort.sortfields.add key:=range("a1"), _     sorton:=xlsortonvalues, order:=xldescending, dataoption:= _     xlsorttextasnumbers activeworkbook.worksheets("abc").sort     .setrange range("a2:k187")     .header = xlno     .matchcase = false     .orientation = xltoptobottom     .sortmethod = xlpinyin     .apply end    application.goto reference:="xyz!rc" activeworkbook.worksheets("xyz").sort.sortfields.clear activeworkbook.worksheets("xyz").sort.sortfields.add key:=range("a1"), _     sorton:=xlsortonvalues, order:=xldescending, dataoption:= _     xlsorttextasnumbers activeworkbook.worksheets("xyz").sort     .setrange range("a2:j179")     .header = xlno     .matchcase = false     .orientation = xltoptobottom     .sortmethod = xlpinyin     .apply end  end sub 

since using "with" can combine 1 bigger statement:

with activeworkbook.worksheets("abc").sort     .sortfields.clear     .sortfields.add key:=range("a1"), _     sorton:=xlsortonvalues, order:=xldescending, dataoption:= _     xlsorttextasnumbers     .setrange range("a2:k187")     .header = xlno     .matchcase = false     .orientation = xltoptobottom     .sortmethod = xlpinyin     .apply end 

also, can remove .header, .matchcase, .orientation, .sortmethod if don't need sort those.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -