我正在创建一个代码,用于复制列g中的公式,然后按升序对列g进行排序。我正在接收一个范围错误的方法,我的代码选择列a:g进行排序。我提供了下面的代码。感谢所有帮助!
谢谢!
Sub Sorting()
Dim ws As Worksheet
Set ws = Worksheets("FedEx Air Ops Workbench Report")
lastrow = ws.Cells(ws.Rows.Count, "E").End(xlUp).Row
Debug.Print lastrow
ws.Range("G1").FormulaR1C1 = "=VLOOKUP(RC[-2],BUTTONS!R2C9:R6C10,2,FALSE)"
ws.Range("G1").AutoFill Destination:=ws.Range("G1:G" & lastrow), Type:=xlFillDefault
With ws.Columns("A:G").Sort
.SetRange ws.Range("A1:G" & lastrow)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub