VBA - “错误数量的参数或无效的属性分配” - Cells()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22889634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 02:40:38  来源:igfitidea点击:

VBA - "Wrong number of arguments or invalid property assignment" - Cells()

excelvbaexcel-vba

提问by Soran

Following a tutorial for arrays on VBA Excel. As you can see, just about everything is commented out and I still get this error. If I use Range("A1", "A1").Value = 1there's no problem. I also noticed that the intelisense doesn't pick up 'Cells('

遵循 VBA Excel 上的数组教程。如您所见,几乎所有内容都被注释掉了,但我仍然收到此错误。如果我使用Range("A1", "A1").Value = 1没有问题。我还注意到智能感知没有接收到 'Cells('

Option Explicit

Sub ArrayTest()

'Dim arrayint(1 To 5) As Integer
'Dim i As Integer
'Dim j As Integer


'    For j = 1 To UBound(arrayint)
'        arrayint(j) = 10 * j
'    Next j

'    For i = i To UBound(arrayint)
        Cells(1, 1).Value = 1 'arrayint(i)
'    Next i

End Sub

回答by L42

Try using Applicationand check if Intellisensepicks up Cellsproperty.
If so, replace your code by this:

尝试使用Application并检查是否Intellisense捡起Cells财产。
如果是这样,请用以下代码替换您的代码:

Application.Cells(1, 1).Value = 1

回答by RANGAN

You have not commented the line

您还没有评论该行

Cells(1, 1).Value = 1 'arrayint(i)

This may be the reason for error.

这可能是错误的原因。