excel - Get the last column character dynamically and pass it -
excel vba: trying last column character dynamically , pass last column while selecting range sorting. doesn't seem work here code
sub sort_that_is_not_called_sort_because_that_is_a_reseved_word() dim lastrowcheck long, n1 long, lastrowcheck1 long, n2 long dim lcol integer, colletter string worksheets("mergesheet") lastrowcheck = .range("a" & .rows.count).end(xlup).row n1 = 2 lastrowcheck if .cells(n1, 1).value = "fund" .rows(n1).delete end if next n1 activeworkbook.worksheets("mergesheet").sort.sortfields.clear activeworkbook.worksheets("mergesheet").sort.sortfields.add key:=range( _ "a2"), sorton:=xlsortonvalues, order:=xlascending, dataoption:= _ xlsortnormal activeworkbook.worksheets("mergesheet").sort lcol = cells(1, columns.count).end(xltoleft).column colletter = converttoletter(lcol) .setrange range("a2:colletter" & lastrowcheck) .header = xlno .matchcase = false .orientation = xltoptobottom .sortmethod = xlpinyin .apply end end end sub
a recorded range.sort method verbose. can typically pare down recorded code small fraction of recorded , end necessary.
sub sort_that_is_not_called_sort_because_that_is_a_reseved_word2() worksheets("mergesheet") .cells(2, 1).currentregion .resize(.rows.count + (.rows(1).row = 1), .columns.count).offset(abs(.rows(1).row = 1), 0) .cells.sort key1:=.columns(1), order1:=xlascending, _ orientation:=xltoptobottom, header:=xlno, _ dataoption:=xlsortnormal, matchcase:=false end end end sub
Comments
Post a Comment