VBA for Excel-设置范围 [英] VBA for Excel - Setting a range
问题描述
我对设定范围有疑问.我正在尝试某些东西,但是它不起作用.假设我有范围r,例如我写过:
I have a question about set range. There is something that I am trying and it's not working. Let's say I have range r, for example I wrote:
set r = range("a1")
但是此范围对活动工作表有效,例如,如果我在worksheet1上并且我写r.value = 1,则它将更改活动工作表上该单元格的值.现在,我想在另一个工作表上更改该特定范围的值.所以我写
But this range is valid for the active worksheet, for example if I am on worksheet1 and I write r.value = 1 then it will change the value of that cell on the active worksheet. Now I want to change the value of that specific range on another worksheet. So I write
worksheets("specificworksheet").r.value =1
但是当我写这篇文章时,它说对象不支持此属性或方法.这是为什么?如何为另一个工作表分配一个范围(已设置)?在这种情况下,写
But when I write this, it says Object doesn't support this propert or method. why is that? How can i assign a range (that was already set) for another worksheet? In this case writing
worksheets("specificworksheet").range("a1").value=1
可以解决我的问题,但是,某些thimesime具有更复杂的范围,例如,如果我将一个单元格赋给r,而我使用cells.find(...). 感谢任何帮助,谢谢!
would solve my problem, however, somethimes I have more complicated range, for example if I assinged a cell to r, where I used cells.find(...). Appreciate any help, thanks!
推荐答案
您可以使用地址:
worksheets("specificworksheet").range(r.Address).value=1
这篇关于VBA for Excel-设置范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!