vba Excel 宏 - for 循环增量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5309807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 11:14:13  来源:igfitidea点击:

Excel macro - for loop increment

excel-vbafor-loopms-officeincrementvba

提问by CustomX

I've looked but can't find a solution.

我已经看过了,但找不到解决方案。

How do you increment a variable? Like in any other language you just do ++(variable name) just before the end of the loop. In my example, I'd like to increment J.

你如何增加一个变量?就像在任何其他语言中一样,您只需在循环结束之前执行 ++(variable name) 即可。在我的例子中,我想增加 J。

Dim j as integer
j = 13
FinalRow = Range("B15").End(xlUp).Row
        For i = 9 To FinalRow
            Range("B" & i).Copy Destination:=Sheets("Design").Range("A" & j)
            J++
        Next i

The code loops from B9-B15 and pastes the information in the Designsheet from A13 and downwards.

代码从 B9-B15 循环,并将信息从 A13 和向下粘贴到设计表中。

回答by Ben

Just do this:

只需这样做:

J = J + 1

Simples.

简单。