对于不连续范围的循环 [英] For loop with non-contiguous range
问题描述
为了参考,我希望它循环浏览列1到80,但是跳过第25,36,37,44,60,63,64,67,68, 73,75和76。
编辑:谢谢你们,但我已经按照你的描述工作了,我正在寻找一种更短更优雅的方法。
编辑2:甚至是VBA?
学习C#的VBA版本的答案: -
Dim col As Integer:For col = 1至70
选择案例col
案例25,36,37,44,60,63,64,67,68,73,75,76
'do nothing'
Case Else
'do something'
End选择
下一个col
I have a loop that runs through each column and sets the value to an R1C1 sum of a few rows above it. I'm using a for loop, but I want to skip a few columns, as they contain formulae already in the cell. How can I set up a loop that only cycles through a non-contiguous set or numbers?
For reference, I want it to cycle through columns 1 to 80, but skip cols 25, 36, 37, 44, 60, 63, 64, 67, 68, 73, 75 and 76.
Edit: thanks guys, but I;ve already got it working as you described; I was looking for a shorter and more elegant method.
Edit 2: Is that even VBA?!
A VBA version of Learning's C# answer:-
Dim col As Integer: For col = 1 To 70
Select Case col
Case 25, 36, 37, 44, 60, 63, 64, 67, 68, 73, 75, 76
'do nothing'
Case Else
'do something'
End Select
Next col
这篇关于对于不连续范围的循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!