[英]VBA Code to sort an Excel Column in Ascending Order and Expand Selection?
我試圖在帶有VBA的excel文件中按升序對列D進行排序。 我想擴展列AF中所有值的選擇。
我用這個公式作為起點:
它只按一列按降序排序。 我找不到更多的例子。
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.