【发布时间】:2019-07-16 17:47:13
【问题描述】:
下面的代码按设定范围内的数据排序
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
lastcol = .Cells(1, Columns.Count).End(xlToLeft).Column
mySheet.Sort.SortFields.Clear
mySheet.Sort.SortFields.Add Key:=Range("A2:A" & lastrow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With mySheet.Sort
.SetRange Range("A1:U" & lastrow)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
每次执行代码时,列数可能会有所不同。有没有办法调整这段代码,使范围同时使用 lastrow 和 lastcol?
【问题讨论】: