EXCEL-VBA通过循环更改范围 [英] EXCEL-VBA Change a range with a loop
问题描述
Set rng = Worksheets("Sheet1").Range("B2")
我具有上述要求,并且希望运行一个循环来更改我使用/评估的范围.我尝试了以下变化.
I have the above and would like to run a loop that changes the range I use/evaluate. I have tried variations of the following.
for x = 2 to 10
Set rng = Worksheets("No-Funding").Range(x & "2")
Next X
我已经进行了一些调查,发现了其他堆栈溢出: Excel VBA循环更改范围的公式在这种情况下,我还是无法理解它.
I have done some investigating and found this other Stack Overflow: Excel VBA Looping formula to change Range I can not make sense of it in this situation though.
我的代码也不能使用单元格,我已经尝试过了,只能使其与Range一起使用.感谢您提供的任何帮助!
My code will not work if it uses cells either, I have tried that and can only make it work with Range. Thanks for any help provided!
推荐答案
对于严格的数字增量尝试,
For a strictly numerical increment try,
Set rng = Worksheets("No-Funding").Cells(x, 2)
可以通过考虑ASCII字符来获得 xlA1
样式参考.
An xlA1
style reference can be achieved by factoring in the ASCII character.
Set rng = Worksheets("No-Funding").Range(Chr(64 + x) & 2)
这篇关于EXCEL-VBA通过循环更改范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!