错误'1004'对象'_Worksheet'的方法'范围'失败

时间:2017-10-12 08:57:37

标签: excel vba range sumifs

我正在尝试为我的变量Arg1指定一个范围。

dim wkb2 as workbook
set wkb2 =  workbooks("File2.xlsx")
dim ws2 as worksheet
set ws2 = wkb2.worksheets(k)

Dim Arg1 As Range 'the range to sum
Dim Arg2 As Range 'criteria1 range`enter code here`
Dim Arg3 As Variant 'criteria1
Dim Arg4 As Range 'criteria2 range
Dim Arg5 As Variant 'criteria2

Set Arg1 = ws2.Range(Cells(i + 2, 6), Cells(i + 2, 6).End(xlDown).Offset(-1, 
0))
Set Arg2 = ws2.Range(Cells(i + 2, 4), Cells(i + 2, 4).End(xlDown))
Set Arg4 = ws2.Range(Cells(i + 2, 5), Cells(i + 2, 5).End(xlDown))
Arg3 = ws1.Cells(j, 20)
Arg5 = ws1.Cells(j, 21)

ws1.Cells(j, 23).Value = Application.WorksheetFunction.SumIfs(Arg1, Arg2, 
Arg3, Arg4, Arg5)

当我设置Arg1 = ...

时,我收到错误(标题中)

我要做的是从Arg1分配一个范围来自Cells(i + 2,6):Cells(i + 2,“使用Ctrl Down后1个单元格更高”)。因此,例如,如果i + 2 = 5,我会想要Range。(“F5:F9”),假设最后一行是Row10。

非常感谢任何帮助! (:

1 个答案:

答案 0 :(得分:0)

如果您将ws1的引用调整为正在使用的工作表

,则应编译以下内容

另外,将变量放在一起。

evaluationDependsOn(':fe')