Excel完全限定范围(Cells(),Cells()) [英] Excel Fully Qualifying Range (Cells(),Cells())
问题描述
在示例中,我已经使用尺寸标注的变量来限定我的工作表。是否需要100%的可靠性才能在范围括号内进一步限定?
dim myWS as Worksheet
设置myWS = Thisworkbook.Activesheet
- 使用方法A?
myWS.Range(Cells(1,5),Cells(500,20))。ClearContents
- 或方法B?
myWS.Range(myWS。细胞(1,5),myWS.Cells(500,20))。ClearContents
范围括号内默认引用被调用的myWS.Range,或者单元格默认引用活动工作表?
如果myWS设置为其他比活动表单,我会从单元格中获得意想不到的结果吗?
这不难,除非我必须回去,在许多地方改变它,如果你说第二种方式是更值得信赖的!
方法A只有在myWS在被叫的时间。方法B更强大,方法C也是如下:
myWS.Range(Cells(1,5).Address,Cells( 500))地址.ClearContents
或方法D:
myWS.Range(E1:T500)
I know many people have talked about fully qualifying ranges. I just want to know how deep you need to go with it to avoid problems.
In the example, I have qualified my worksheet using a dimensioned variable. Is it then necessary to be 100% reliable, to further qualify within the range parentheses?
dim myWS as Worksheet
set myWS = Thisworkbook.Activesheet
-- Use method A?
myWS.Range(Cells(1,5), Cells(500,20)).ClearContents
-- Or method B?
myWS.Range(myWS.Cells(1,5), myWS.Cells(500,20)).ClearContents
Does "Cells" inside Range parentheses default to reference myWS.Range in which it was called or does "Cells" default to reference the active sheet?
If myWS were set to a sheet other than the active sheet, would I get unexpected results from Cells?
It's not hard, except I will have to go back and change it in many places if you say that the second way is more trustworthy!
Method A will only work if you myWS is active at the time of being called. Method B is more robust, as are method C:
myWS.Range(Cells(1,5).Address, Cells(500,20).Address).ClearContents
or method D:
myWS.Range("E1:T500")
这篇关于Excel完全限定范围(Cells(),Cells())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!