Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 排序时的范围错误方法_Excel_Vba - Fatal编程技术网

Excel 排序时的范围错误方法

Excel 排序时的范围错误方法,excel,vba,Excel,Vba,我正在创建一个代码,它将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

我正在创建一个代码,它将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

哈哈,你有吗?此外,我认为这是显而易见的,但你所要做的就是将
lastrow
替换到你所有的
G55
。编辑:忘记您的代码的其余部分是录制的,而不是对象驱动的。无法对工作表进行排序。只有一个范围。我很不幸,因为我一直因为在代码方面做得不好而被责骂,所以我不得不创建另一个帐户,这样人们就不会一直羞辱我。你得了95分,所以在某个时候你做得对。也就是说,您似乎没有在这里投入太多精力XD正如我所说的,您无法对工作表进行排序,只是您的语法似乎很糟糕
sort.SortFields.
findwindow试图说的是将
ws.sort
替换为
ws.Columns(“a:G”).sort
。/希望如此!编辑:你最好不要去度假