我需要你的帮助。
如果我正在运行此代码,则不会出现问题(请注意Sheet1.Range("F2:BL6991"))
Colnumber = Sheet2.Range("A1").End(xlToRight).Column
'MsgBox (Colnumber)
For j = 3 To Colnumber
For i = 2 To Rownumber
Sheet2.Cells(i, j).Value = Application.WorksheetFunction.SumIfs(Sheet1.Range("F2:BL6991"), Sheet1.Range("E2:E6991"), Sheet2.Cells(i, 1))
Next i
Next j
但是当我尝试更改此代码时:(我将代码从 Sheet1.Range("F2:BL6991") 更改为 Sheet1.Range(cells(2,j+3), cells(6991, j+3)))
Colnumber = Sheet2.Range("A1").End(xlToRight).Column
'MsgBox (Colnumber)
For j = 3 To Colnumber
For i = 2 To Rownumber
Sheet2.Cells(i, j).Value = Application.WorksheetFunction.SumIfs(Sheet1.Range(cells(2,j+3), cells(6991, j+3)) , Sheet1.Range("E2:E6991"), Sheet2.Cells(i, 1))
Next i
Next j
它给了我错误1004。
即使我使用了这段代码,它也给了我错误:
Sheet1.Range(cells(2,6), cells(6991, 6))
或者
Sheet2.Cells(i, j).Value = varResult
varResult = Application.WorksheetFunction.SumIfs( _
Arg1:=Sheet1.Range(Cells(2, 6), Cells(6991, 6)), _
Arg2:=Sheet1.Range("E2:E6991"), _
Arg3:=Sheet2.Cells(i, 1))
你能指导我哪里做错了以及如何解决它吗?
TIA