我最近进入Excel宏开发很长一段时间没有必要。Excel VBA长度在一个范围
我有一列有两百行,其中每行都有一个值。我编写了一个循环来遍历每一行值,读取当前值,然后将值写回去掉最后一个字符。
这里是我写的一些实际(和伪)代码。
Dim theRow as Long
Dim totRow as Long
Dim fooStr as String
theRow = 2 'we begin on the second row of the colummn
totRow = 201 'there are 200 values
For theRow = 2 to totRow
fooStr = WorkSheets(DestSheet).Cells(theRow,"A").Formula 'read the cell value
fooStr = Left(fooStr,Len(fooStr)-1 'subtract the last character from the value
Cells(theRow,1).Value = fooStr 'write the value back
Next theRow
在我做了一些阅读之后,我了解到最好的做法是使用Range来读取和写入数值。是否有可能使用Range重写我正在做的事情,这样它会变得更快。
这是我到目前为止所提出的。
Range("A2:A201").Value = Len(Range.Left("A2:A201").Value)-1
但是,这是行不通的。
如果这确实可行,那么如何做到这一点的任何线索?
感谢您的任何提示。
您是否在讨论循环范围中的每个元素?我相信还有一个循环,我认为你不能一次完成。 – jonsca 2011-05-18 03:40:59