大佬教程收集整理的这篇文章主要介绍了多次重印行并进行修改,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Sub computeThis()
Dim rng As Range
Dim row As Range
Dim cell As Range
Set rng = Range("A2:D3")
For Each row In rng.Rows 'Throws no error but doesn't seem to loop twice either'
Dim i As Integer
'Set the starTing cell number'
Dim x As Integer
x = 2
'Repeat 12 times..'
For i = 1 To 12
'..with new values'
Cells(x,6).Value = Range("A2").Value 'Needs to update with each loop'
Cells(x,7).Value = i 'Works OK'
Cells(x,8).Value = Range("C2").Value 'Needs to update with each loop'
Cells(x,9).Value = Range("D2").Value / 12 'Needs to update with each loop'
x = x + 1
Next i
Next row
End Sub
@H_262_25@
@H_696_2@问题如下:
X
在外循环开始时被重置为 2,因此看起来它运行了一次,但实际上覆盖了您的第一个循环。
@H_696_2@我添加了一个新变量来增加行号。我还将您的类型从 Integer 更改为 Long,不要在 VBA 中使用 Integer 类型,否则会导致溢出错误。
Sub computeThis()
Dim rng As Range
Dim row As Range
Dim cell As Range
Set rng = Range("A2:D3")
Dim x As Long
x = 2
Dim j As Long
j = 2
For Each row In rng.Rows 'Throws no error but doesn't seem to loop twice either'
Dim i As Long
'Repeat 12 times..'
For i = 1 To 12
'..with new values'
Cells(j,6).Value = Range("A" & X).Value 'Needs to update with each loop'
Cells(j,7).Value = i 'Works OK'
Cells(j,8).Value = Range("C" & X).Value 'Needs to update with each loop'
Cells(j,9).Value = Range("D" & X).Value / 12 'Needs to update with each loop'
j = j + 1
Next i
x = x + 1
Next row
End Sub
@H_262_25@
以上是大佬教程为你收集整理的多次重印行并进行修改全部内容,希望文章能够帮你解决多次重印行并进行修改所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。