|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
比如说排序前光标在60行,大概在屏幕的中间位置,排序之后,这行数据到了80行。
用VBA排序之后,屏幕会自动滚到首行,光标所在当前行还是在60行。
如何才能在排序后,光标还是定位到这行数据上(也就是排序后的80行),并滚动到屏幕中间。
- ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Clear
- ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Add Key:=Range("M:M"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
- ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Add Key:=Range("O:O"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
- ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Add Key:=Range("B:B"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
- ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Add Key:=Range("C:C"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
- ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Add Key:=Range("P:P"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
- ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Add Key:=Range("E:E"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
- ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Add Key:=Range("F:F"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
- With ActiveWorkbook.ActiveSheet.AutoFilter.Sort
- .Header = xlYes
- .MatchCase = False
- .Orientation = xlTopToBottom
- .SortMethod = xlPinYin
- .Apply
- End With
复制代码
|
|