我正在尝试在单独的工作表中对范围进行排序.但是,我一直收到这条消息:
'1004': "The sort reference is not valid. Make sure it's within the data you want to sort, and the first Sort By box isn't the same or blank.
Run Code Online (Sandbox Code Playgroud)
我检查了范围,它们都存在并且正在工作.
代码如下:
Dim EmpBRange As String
EmpBRange = Sheets("EmployeeData").Cells(Cells.Rows.Count, "B").End(xlUp).Row
Worksheets("EmployeeData").Range("K3:K" & EmpBRange).Sort Key1:=Range("K3:K" & EmpBRange), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Run Code Online (Sandbox Code Playgroud)
提前致谢
Dou*_*ncy 26
我怀疑你需要完全限定Key1范围,因为你从另一张表中调用代码:
Worksheets("EmployeeData").Range("K3:K" & EmpBRange).Sort Key1:=Worksheets("EmployeeData").Range("K3:K" & EmpBRange)
Run Code Online (Sandbox Code Playgroud)
这通常是一个好主意.
| 归档时间: |
|
| 查看次数: |
24231 次 |
| 最近记录: |