Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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
Vba 范围类的排序方法失败运行时错误1004_Vba_Excel - Fatal编程技术网

Vba 范围类的排序方法失败运行时错误1004

Vba 范围类的排序方法失败运行时错误1004,vba,excel,Vba,Excel,当我尝试对脚本中的列进行排序时,它返回range class failed运行时错误1004的错误排序方法。下面我介绍了调试此错误的脚本以及脚本中使用的声明 Set SbA = Worksheets("SumByAddress") Set SbM = Worksheets("SumByMeterSize") Set SFD = Worksheets("ShortFormData") Counter = 2 premiseID = "" RowNew = 2 TotalRows = SFD.Cel

当我尝试对脚本中的列进行排序时,它返回range class failed运行时错误1004的错误排序方法。下面我介绍了调试此错误的脚本以及脚本中使用的声明

Set SbA = Worksheets("SumByAddress")
Set SbM = Worksheets("SumByMeterSize")
Set SFD = Worksheets("ShortFormData")
Counter = 2
premiseID = ""
RowNew = 2
TotalRows = SFD.Cells(1, 1).End(xlDown).Row
Application.Calculation = xlCalculationManual
TimeStart = Now
PrevUpdate = Now
SFD.Range("M15") = "Creating summation by address"
Application.ScreenUpdating = False

SFD.Range("A:I").Sort , _
key2:=Range("A2"), order2:=xlAscending, Header:=xlYes, MatchCase:=True, _
key3:=Range("D2"), order3:=xlAscending, Header:=xlYes, MatchCase:=True

在指定Key2和Key3之前,需要指定Key1。例如:

Private Sub sortSheet(ByRef sh As Excel.Worksheet, ByVal rc As String)
  Dim lastRow As Long
  lastRow = sh.Cells(sh.rows.count, "A").End(xlUp).row
  With sh.Range("A1:" + rc + CStr(lastRow))
    .Sort Key1:=sh.Range("B1"), Order1:=xlAscending, _
        Key2:=sh.Range("A1"), Order2:=xlAscending, _
        Header:=xlYes, _
        MatchCase:=False, _
        Orientation:=xlTopToBottom
  End With
End Sub

此外,
标题
匹配案例
只应指定一次

在指定Key2和Key3之前,需要指定Key1。例如:

Private Sub sortSheet(ByRef sh As Excel.Worksheet, ByVal rc As String)
  Dim lastRow As Long
  lastRow = sh.Cells(sh.rows.count, "A").End(xlUp).row
  With sh.Range("A1:" + rc + CStr(lastRow))
    .Sort Key1:=sh.Range("B1"), Order1:=xlAscending, _
        Key2:=sh.Range("A1"), Order2:=xlAscending, _
        Header:=xlYes, _
        MatchCase:=False, _
        Orientation:=xlTopToBottom
  End With
End Sub
此外,
标题
匹配案例
只应指定一次