使用下面的代码,我得到一个错误:
Run-time error '1004' Method 'Range' of object'_Worksheet failed.
Dim destLastCol As Integer 'last column in range
Dim destLastRow As Integer 'last row in range
Dim wsCrewDetail As Worksheet '
Set wsCrewDetail = Worksheets("CrewDetail_M")
destLastCol = integer assigned previously
destLastRow = integer assigned previously
With wsCrewDetail.Range(Cells(4, 1), Cells(destLastRow, destLastCol)) <== error here
.Sort Key1:=.Cells(4, 2), Order1:=xlAscending, _
key2:=.Cells(4, 1), Order2:=xlAscending, _
key3:=.Cells(4, 3), order3:=xlAscending, Header:=xlYes
End With
我已经搜索并查看了许多示例,尝试了许多设置Range
参考的变体,但没有任何效果。
请问什么是正确的参考语法?
编辑添加 destLastRow = 先前分配的整数并编辑以显示 destLastCol