VBA Excel范围()与单元格参数 [英] VBA Excel Range() with Cell argument
问题描述
为什么以下不起作用:
范围(单元格(1,1))。值= 3
细胞(1,1)
本质上应该与使用 A1相同
对吗?
Cells(1,1)
should essentially be the same thing as using A1
right?
(我意识到我可以做 Cells(1,1).Value = 3
,但我只是好奇为什么它不起作用。)
(I realize that I could just do Cells(1,1).Value = 3
, but I'm just curious as to why it doesn't work.)
我阅读了MSDN条目和它表明第一个参数必须是 A1
样式,但这样的东西可以正常工作:
I read the MSDN entry and it shows that the first argument must be A1
style, yet something like this does work:
范围(单元格(1,1),单元格(2,3))。值= 2
完全混淆。 >
Totally confused.
推荐答案
当您想使用Cells属性指定范围对象的参数(如果我记得正确 - 我没有使用VBA一段时间),那么你必须有效地提供两个参数。
When you want to use the Cells property to specify the parameters of the range object (if I remember rightly - I've not been using VBA for some time), then you have to effectively supply two arguments.
所以如果你想引用只有一个单元格的范围对象,那么你需要写:
So if you want to reference a range object that has only one cell, then you need to write:
Range(Cells(1, 1), Cells(1, 1)).value = "Hello World"
这篇关于VBA Excel范围()与单元格参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!