vba循环语句

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vba循环语句相关的知识,希望对你有一定的参考价值。

Sheets("分组统计表").Cells(D, 2) = Sheets("分组统计表").Cells(E, 2) 其中D E 是两个整数变量,D要求22到2000,而且D的赋值有特殊要求, D=22....31, 赋10个数值,32到36的值不能赋给D; D=37....46,再赋10个数值,47到51的值也不能赋给D ;D=52....61,赋10个数值,....依次循环到两千。 E的要求比较简单,E=4....13,赋10个数;E=4....13,再赋值10个数;E=4....13,再赋值10个数....一直循环下去。 麻烦大侠说下代码,谢谢了

参考技术A 循环变量是可以在循环体内改变的。
E
=
1
For
D
=
E
+
21
To
2000
Sheets("分组统计表").Cells(D,
2)
=
Sheets("分组统计表").Cells(E
+
3,
2)
If
E
>
10
Then
E
=
1
D
=
D
+
4
Else
E
=
E
+
1
End
If
Next

vba行列循环语句

For i = 3 To ThisWorkbook.Sheets(1).[a65536].End(xlUp).Row
With template.Sheets("??")
.Cells(5, "r") = ThisWorkbook.Sheets(1).Cells(3, "b")
.Cells(5, "u") = ThisWorkbook.Sheets(1).Cells(3, "v")
.Cells(7, "i") = ThisWorkbook.Sheets(1).Cells(3, "p")
.Cells(7, "n") = ThisWorkbook.Sheets(1).Cells(3, "n")
.Cells(7, "q") = ThisWorkbook.Sheets(1).Cells(3, "c")
.Cells(8, "i") = ThisWorkbook.Sheets(1).Cells(3, "o")
.Cells(8, "n") = ThisWorkbook.Sheets(1).Cells(3, "q")
.Cells(8, "q") = ThisWorkbook.Sheets(1).Cells(3, "k")
.Cells(9, "ac") = ThisWorkbook.Sheets(1).Cells(3, "t")
.Cells(9, "ad") = ThisWorkbook.Sheets(1).Cells(3, "u")
.Cells(10, "i") = ThisWorkbook.Sheets(1).Cells(3, "l")
.Cells(10, "n") = ThisWorkbook.Sheets(1).Cells(3, "r")
.Cells(10, "q") = ThisWorkbook.Sheets(1).Cells(3, "m")
.Cells(11, "ac") = ThisWorkbook.Sheets(1).Cells(3, "f")
想让后面3行循环 4 5 6 7 .。。。这个代码该怎样写啊求助

把 with 区域内后面的数字3都改成i就好了。 参考技术A Dim J, K As Integer
For J = 1 To [A63336].End(xlUp).Row
For K = 1 To 20 '假设表有20列
代码 (要做事)
next K
next J追问

请问这段代码要插入哪里合适

以上是关于vba循环语句的主要内容,如果未能解决你的问题,请参考以下文章

vba循环语句

Excel VBA中for循环语句的用法

Excel VBA中for循环语句的用法

vba基础二 条件判断语句和循环语句总结

20160127:开始学VBA:循环语句

VBA学习笔记之循环