Art*_*ski 5 excel vba excel-vba
我的代码有问题,出现错误,我不明白为什么.错误是:
"编译错误:下一个没有For"
我不明白为什么会这样.我是编码的新手,所以任何帮助和评论都非常受欢迎.
这是代码,Next指向没有For的那个代码提供了注释.
Sub CGT_Cost()
startrow = Worksheets("GUTS").Cells(10, 1) 'Here I put 1
endrow = Worksheets("GUTS").Cells(11, 1) 'Here I put 1000
For x = endrow To startrow Step -1
If Cells(x, "Q").Value = "Sale" Then
If Cells(x, "D").Value = "1" Then
For i = 1 To 1000
If Cells(x - i, "R").Value <> "1" Then
Next i
Else
Range("G" & x).FormulaR1C1 = "=R[-" & i & "]C/R[-" & i & "]C[-1]*RC[-1]"
End If
End If
End If
Next x
End Sub
Run Code Online (Sandbox Code Playgroud)
感谢所有人,最诚挚的问候,
Artur.
具有正文的每个For语句必须具有匹配的Next,并且具有正文的每个If-Then语句必须具有匹配的End If.
例:
For i = 1 To 10 '<---- This is the header
Hello(i) = "Blah" '<---- This is the body
Next i '<---- This is the closing statement
Run Code Online (Sandbox Code Playgroud)
你在For i循环中有一部分If语句的主体,而它的一部分在外面.它必须是ALL inside或ALL outside.仔细考虑逻辑,看看你想做什么.
| 归档时间: |
|
| 查看次数: |
81116 次 |
| 最近记录: |