Excel VBA循环列 [英] Excel VBA Loop on columns
问题描述
当我们要在行中循环时,我们可以使用如下代码:
i = 1
Do
Range(E&&D&D&I)。选择
i = i + 1
循环直到我& 10
但是如果我们想在列上执行循环怎么办?
我们可以使用与上述相同的方法吗?
而Excel中的列是复杂的,如A,B,C,.. 。,Y,Z,AA,AB,AC,...等
从Z到AA的循环之间会出现问题。
我们如何循环使用字母表列从A到Z,然后继续进入AA,AB等等
有什么吗可以帮助吗?
是的,我们使用选择
/ p>
示例代码:列(A)。选择
如何循环浏览列:
方法1 :(可以使用索引替换Excel地址)
对于i = 1到100
列(i)。选择
next i
方法2:(使用地址)
对于i = 1 To 100
列(列(i).Address)。选择
下一个i
编辑:
剥离OP的列
columnString = Replace(Split(Columns(27).Address,:)(0),$,)
eg你想得到第27列 - > AA,你可以这样得到
when we are going to do a loop in the rows, we can use code like the following:
i = 1
Do
Range("E" & i & ":D" & i).Select
i = i + 1
Loop Until i > 10
but what if we want to do a loop on a column?
Can we use the same method as above?
while the columns in Excel is a complex such as A, B, C, ..., Y, Z, AA, AB, AC, ..., etc. problems will arise between loop from the "Z" to the "AA".
how we do looping alphabet column from "A" to "Z" and then continued into "AA", "AB" and so on
is there anything that can help?
Yes, let's use Select
as an example
sample code: Columns("A").select
How to loop through Columns:
Method 1: (You can use index to replace the Excel Address)
For i = 1 to 100
Columns(i).Select
next i
Method 2: (Using the address)
For i = 1 To 100
Columns(Columns(i).Address).Select
Next i
EDIT: Strip the Column for OP
columnString = Replace(Split(Columns(27).Address, ":")(0), "$", "")
e.g. you want to get the 27th Column --> AA, you can get it this way
这篇关于Excel VBA循环列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!