就是。在.范围内,必要时由.Cells定义?人们普遍认为,这不是“最佳实践”。dim rng as rangewith thisworkbook '<~~ possibly set an external workbook
with .worksheets("sheet1")
set rng = .range(cells(2, 1), cells(rows.count, 1).end(xlup))
end withend with两人Rang.Cells属性定义距离对象将默认为ActiveSheet属性..如果这不是Sheet 1(定义为.父母在带着.。以语句结尾),任务将失败,Run-tim error '1004': Application-defined or object-defined error解决方案:使用.Cells不Cells..案子结了。但是.。是.在这方面是必要的距离对象定义时,两个Rang.Cells属性继承.父母属性中定义的工作表属性。带着.。以语句结尾?这怎么能dim rng as rangewith thisworkbook '<~~ possibly set an external workbook
with .worksheets("sheet1")
' define rng as Sheet1!A2 to the last populated cell in Sheet1!A:A
set rng = .range(.cells(2, 1), .cells(rows.count, 1).end(xlup)) '<~~ .range
end withend withdebug.print rng.address(0, 0, external:=true)..与此不同,dim rng as rangewith thisworkbook '<~~ possibly set an external workbook
with .worksheets("sheet1")
' define rng as Sheet1!A2 to the last populated cell in Sheet1!A:A
set rng = range(.cells(2, 1), .cells(rows.count, 1).end(xlup)) '<~~ range not .range
end withend withdebug.print rng.address(0, 0, external:=true)我们用.range当定义范围的参数不明确时;.range([A1])这个A1单元格可以来自任何工作表,并且将默认为ActiveSheet属性没有...但是,当定义Range对象的作用域正确引用其父工作表时,为什么需要引用Range对象的父对象呢?
3 回答
慕哥9229398
TA贡献1877条经验 获得超6个赞
是
假想
测试1(从模块运行)
测试2(从Sheet 1的工作表代码区域运行)
测试3(从Sheet 2的工作表代码区域运行)
'~~> This code failsset rng = range(.cells(2, 1), .cells(rows.count, 1).end(xlup))
Application Defined or Object defined
PIPIONE
TA贡献1829条经验 获得超9个赞
.
Worksheet
set rng = .range(.cells(...), .cells(...))
set rng = range(.cells(...), .cells(...))
.
Worksheet
.
添加回答
举报
0/150
提交
取消