选择不同的列范围Excel VBA [英] Select Different Column Range Excel VBA
问题描述
所以在excel vba中,我试图选择一个范围,但是每次都选择一个不同的范围.我有一个循环,但是我想知道如何实际编写代码来更改范围.这是单个范围的样子.
So in excel vba I'm trying to select a range, but a different range every time. I have a loop going, but I was wondering how I would actually write the code to change the range. This is what it would look like for a single range.
Range("B7").Select
有没有办法用整数代替字符串,例如"B7"
Is there a way to do this with integers instead of strings such as "B7"
即
Range(i).Select
我需要它来选择单个列.任何建议将不胜感激.
I need it to select a single column. Any advice would be appreciated.
谢谢
推荐答案
如果您知道单元格相对于起始行的位置,则可以使用offset来执行以下操作:
If you know where the cell is relative to the starting row you could use offset to do something like this:
dim rng as Range
dim i as integer
set rng = range("B7")
for i=0 to 10
rng.offset(0,i).select
next i
查找偏移量以了解如何根据您的需要进行修改
Look up offset to learn how to modify this to suit your needs
这篇关于选择不同的列范围Excel VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!