VBA循环的问题
a=Range("B2").Valueg=Range("C2").Value/100c=1n=0again:n=n+1c=1+(n*(c/a))b=1/cIfb>=gTh...
a = Range("B2").Value
g = Range("C2").Value / 100
c = 1
n = 0
again:
n = n + 1
c = 1 + (n * (c / a))
b = 1 / c
If b >= g Then GoTo again
Range("C2").Value = n
EXCEL表第一行为标题,从以上代码可以得出C2的值.如果有多行,该如何循环填充值.假设有100行.
完整代码,供大家参考.
Sub erl()
Sheets("sheet1").Select
For i = 2 To 100
a = Range("b" & i & "").Value
g = Range("C" & i & "").Value / 100
c = 1
n = 0
again:
n = n + 1
c = 1 + (n * (c / a))
b = 1 / c
If b >= g Then GoTo again
Range("D" & i & "").Value = n
Next i
End Sub 展开
g = Range("C2").Value / 100
c = 1
n = 0
again:
n = n + 1
c = 1 + (n * (c / a))
b = 1 / c
If b >= g Then GoTo again
Range("C2").Value = n
EXCEL表第一行为标题,从以上代码可以得出C2的值.如果有多行,该如何循环填充值.假设有100行.
完整代码,供大家参考.
Sub erl()
Sheets("sheet1").Select
For i = 2 To 100
a = Range("b" & i & "").Value
g = Range("C" & i & "").Value / 100
c = 1
n = 0
again:
n = n + 1
c = 1 + (n * (c / a))
b = 1 / c
If b >= g Then GoTo again
Range("D" & i & "").Value = n
Next i
End Sub 展开
2个回答
展开全部
做个for循环:
For i As Integer = 1 To 100
a = Range("B" + i.ToString()).Value
g = Range("C" + i.ToString())).Value / 100
c = 1
n = 0
again:
n = n + 1
c = 1 + (n * (c / a))
b = 1 / c
If b >= g Then GoTo again
Range("C"+ i.ToString())).Value = n
Next i
For i As Integer = 1 To 100
a = Range("B" + i.ToString()).Value
g = Range("C" + i.ToString())).Value / 100
c = 1
n = 0
again:
n = n + 1
c = 1 + (n * (c / a))
b = 1 / c
If b >= g Then GoTo again
Range("C"+ i.ToString())).Value = n
Next i
追问
你的语法有点问题,不够细致严谨,比如G=括号多一个,我修正了可以用,谢谢.以下为正确代码
For i = 2 To 100
a = Range("b" & i & "").Value
g = Range("C" & i & "").Value / 100
c = 1
n = 0
again:
n = n + 1
c = 1 + (n * (c / a))
b = 1 / c
If b >= g Then GoTo again
Range("D" & i & "").Value = n
Next i
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
m = 0
again1:
a = Range("B" & m).Value
g = Range("C" & m).Value / 100
c = 1
n = 0
again:
n = n + 1
c = 1 + (n * (c / a))
b = 1 / c
If b >= g Then GoTo again
Range("C" & m).Value = n
If m <= 100 Then GoTo again1
again1:
a = Range("B" & m).Value
g = Range("C" & m).Value / 100
c = 1
n = 0
again:
n = n + 1
c = 1 + (n * (c / a))
b = 1 / c
If b >= g Then GoTo again
Range("C" & m).Value = n
If m <= 100 Then GoTo again1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询