vba 使用“单元格”引用的范围引用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13260311/
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-11 18:23:03  来源:igfitidea点击:

Range reference using "Cells" references

excel-vbavbaexcel

提问by user446667

I'm using long variables to denote columns and rows. When I try to specify a range by the type sheetname.range(cells(i,j), cells(i+1, j+1))I'm getting a Method Range of Object Worksheet failederror.

我使用长变量来表示列和行。当我尝试按类型指定范围时,sheetname.range(cells(i,j), cells(i+1, j+1))出现方法Range of Object Worksheet failed错误。

Any ideas on how to use a range when using long variables as cell references?

关于在使用长变量作为单元格引用时如何使用范围的任何想法?

回答by Tim Williams

sheetname.Range(sheetname.Cells(i,j), sheetname.Cells(i+1, j+1)) 

An unqualified Cells()will always refer to the active sheet.

不合格的Cells()将始终引用活动工作表。

I'd rather use:

我宁愿使用:

sheetname.Cells(i,j).Resize(2,2)