'1004':“排序引用无效”。 [英] '1004': "The sort reference is not valid."

查看:371
本文介绍了'1004':“排序引用无效”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在单独的表单中对范围进行排序。
但是,我不断收到以下消息:

 '1004':排序参考无效,请确保在您要排序的数据中,第一个排序方式框不相同或为空。

我检查了范围,它们都存在并正在工作。



代码如下:

  Dim EmpBRange As String 

EmpBRange = Sheets(EmployeeData)。Cells(Cells.Rows.Count,B)。End(xlUp).Row $ key(K3:K& EmpBRange),Order1:= xlAscending,Header:= xlGuess,_
OrderCustom:= 1,MatchCase:= False,Orientation:= xlTopToBottom,_
DataOption1:= xlSortNormal

提前感谢

解决方案

我怀疑您需要完全符合 Key1 范围,因为您正在从不同的表格调用代码:

  Worksheets(EmployeeData)。Range(K3:K& Emprobange).Sort Key1:= Worksheets(EmployeeData)。Range(K3:K& EmpBRange)

这通常是个好主意。


I am trying to sort a range within a separate sheet. However, I keep getting this message:

 '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. 

I have checked the ranges and they all exist and are working.

The code is below:

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

Thanks in advance

解决方案

I suspect you need to fully qualify the Key1 range, because you are calling the code from a different sheet:

Worksheets("EmployeeData").Range("K3:K" & EmpBRange).Sort Key1:=Worksheets("EmployeeData").Range("K3:K" & EmpBRange)

This is generally a good idea.

这篇关于'1004':“排序引用无效”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆