【问题标题】:VBA Code to sort an Excel Column in Ascending Order and Expand Selection?VBA代码以升序对Excel列进行排序并扩展选择?
【发布时间】:2016-11-04 22:14:59
【问题描述】:

我正在尝试使用 VBA 对 Excel 文件中的 D 列进行升序排序。我想扩大 A-F 列中所有值的选择范围。

我以这个公式为起点:

sort ascending/descending vba excel

它只对一列进行降序排序。我无法找到更多示例。

LastRow = .Cells(.Rows.Count, "D").End(xlUp).Row

If (.Range("D2").Value > .Range("D" & CStr(LastRow))) Then
    xlSort = xlAscending
End If

.Range("D2:D" & LastRow).Sort Key1:=.Range("D2"), Order1:=xlSort, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

【问题讨论】:

标签: vba sorting excel


【解决方案1】:

答案如下:

.Range("D1") = "Index"
.Columns("A:F").Sort key1:=Range("D2"), _
order1:=xlAscending, Header:=xlYes

感谢simoco的评论!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-03
    • 2019-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多