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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/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 创建排序时类型不匹配_Vba_Excel_Sorting - Fatal编程技术网

Vba 创建排序时类型不匹配

Vba 创建排序时类型不匹配,vba,excel,sorting,Vba,Excel,Sorting,我不断发现以下代码的类型不匹配,尤其是SortFields.Add行。我想知道是什么导致了这个问题?谢谢 worksheet.select With worksheet.Sort .SortFields.Clear .SortFields.Add(Rng, xlSortOnCellColor, xlAscending, , xlSortNormal). _ SortOnValu

我不断发现以下代码的类型不匹配,尤其是
SortFields.Add
行。我想知道是什么导致了这个问题?谢谢

worksheet.select
With worksheet.Sort
            .SortFields.Clear
            .SortFields.Add(Rng, xlSortOnCellColor, xlAscending, , xlSortNormal). _
                                    SortOnValue.Color = RGB(255, 255, 0)
            .SetRange = consolidated_sheet.Range("A3:K" & row)
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With

也许你在追求这个:

With worksheet.Sort
        .SortFields.Clear
        .SortFields.Add rng, xlSortOnCellColor, xlAscending, , xlSortNormal
        .SortOnValue.Color = RGB(255, 255, 0)
        .SetRange consolidated_sheet.Range("A3:K" & row)
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
End With
在代码中,您有:

  • 包含SortFields.Add()方法参数的不需要的括号

  • 在延续线之前的点,而不是相反的点

您必须:

  • 已将rng声明为有效的
    范围
    参考

您需要发布更多代码。什么是
Rng