繁体   English   中英

VBA代码按升序排序Excel列并展开选择?

[英]VBA Code to sort an Excel Column in Ascending Order and Expand Selection?

我试图在带有VBA的excel文件中按升序对列D进行排序。 我想扩展列AF中所有值的选择。

我用这个公式作为起点:

排序升序/降序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

这是答案:

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

感谢simoco的评论!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM