[英]How do I sort the amounts in this excel column in Ascending order once the macro is run?
I can't get the values I enter into column D to be sorted by ascending order. 我无法将我输入D列的值按升序排序。
Sheets("Template").Select
Range("A2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
Sheets("OutPut").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Sort Key1:=Range("D1"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers```
Perhaps like this? 也许是这样的?
Sub tgr()
Dim wb As Workbook
Dim wsTemplate As Worksheet
Dim wsOutput As Worksheet
Dim rCopy As Range
Set wb = ActiveWorkbook
Set wsTemplate = wb.Worksheets("Template")
Set wsOutput = wb.Worksheets("OutPut")
Set rCopy = wsTemplate.Range("A2", wsTemplate.Cells.SpecialCells(xlCellTypeLastCell))
With wsOutput.Range("A1").Resize(rCopy.Rows.Count, rCopy.Columns.Count)
.Value = rCopy.Value
.Sort Intersect(.Cells, .Parent.Columns("D")), xlAscending, Header:=xlYes, OrderCustom:=1, DataOption1:=xlSortTextAsNumbers
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.