Excel VBA - 在范围内增加列引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44280296/
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
Excel VBA - increment column reference in range
提问by Boosted_d16
How do I increment the column reference in the code below? Just the column ref, the row values can stay the same.
如何在下面的代码中增加列引用?只是列引用,行值可以保持不变。
Range("w3:w54").PasteSpecial
I'm hoping I can do something like this:
我希望我能做这样的事情:
For i = 23 to 27
'start at column w (which is number 23)
Range(Columns(i)+"3":Columns(i)+"54").PasteSpecial
Next
But that throws an error.
但这会引发错误。
Any suggestions?
有什么建议?
回答by Shai Rado
You can use the Cells(Row, Column)
, so you increment the Column
part easily with the numeric value, without using a conversion function from Numeric to Alphabetical.
您可以使用Cells(Row, Column)
,因此您可以Column
轻松地使用数值增加部分,而无需使用从数字到字母的转换函数。
For i = 23 To 27
'start at column w (which is number 23)
Range(Cells(3, i), Cells(24, i)).PasteSpecial
Next