对于不连续范围的循环 [英] For loop with non-contiguous range

查看:180
本文介绍了对于不连续范围的循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个循环遍历每一列,并将值设置为上面几行的R1C1和。我正在使用for循环,但是我想跳过几列,因为它们包含单元格中已经存在的公式。我如何设置循环,只循环不连续的集合或数字?



为了参考,我希望它循环浏览列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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆