下面粘贴是我写的代码的一部分,而运行相同的,我得到NEXT没有FOR错误。下一个没有错误的Excel VBA
我运行了没有这部分的代码,以确保在下面的代码之前的for/if循环代码中没有其他语法错误。
Dim M As Integer
M = 24
For i = 7 To 19 Step 1
If ActiveSheet.Cells(7, i) >= 0 And ActiveSheet.Cells(8, i) <= 15 Then
ActiveSheet.Cells(M, 6) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(8, i))/30 * 100
End If
If ActiveSheet.Cells(7, i) >= 345 And ActiveSheet.Cells(8, i) <= 360 Or ActiveSheet.Cells(7, i) >= 345 And ActiveSheet.Cells(8, i) <= 0 Then
ActiveSheet.Cells(M, 6) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(8, i))/30 * 100
End If
If ActiveSheet.Cells(7, i) >= ActiveSheet.Cells(23, 6) Then
If ActiveSheet.Cells(8, i) <= ActiveSheet.Cells(23, 7) Then
ActiveSheet.Cells(M, 6) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(7, i))/30 * 100
Else
ActiveSheet.Cells(M, 6) = (ActiveSheet.Cells(23, 7) - ActiveSheet.Cells(7, i))/30 * 100
ActiveSheet.Cells(M, 7) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(23, 7))/30 * 100
End If
If ActiveSheet.Cells(7, i) >= ActiveSheet.Cells(23, 8) Then
If ActiveSheet.Cells(8, i) <= ActiveSheet.Cells(23, 9) Then
ActiveSheet.Cells(M, 7) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(7, i))/30 * 100
Else
ActiveSheet.Cells(M, 7) = (ActiveSheet.Cells(23, 9) - ActiveSheet.Cells(7, i))/30 * 100
ActiveSheet.Cells(M, 8) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(23, 9))/30 * 100
End If
If ActiveSheet.Cells(7, i) >= ActiveSheet.Cells(23, 10) Then
If ActiveSheet.Cells(8, i) <= ActiveSheet.Cells(23, 11) Then
ActiveSheet.Cells(M, 8) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(7, i))/30 * 100
Else
ActiveSheet.Cells(M, 8) = (ActiveSheet.Cells(23, 11) - ActiveSheet.Cells(7, i))/30 * 100
ActiveSheet.Cells(M, 9) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(23, 11))/30 * 100
End If
If ActiveSheet.Cells(7, i) >= ActiveSheet.Cells(23, 12) Then
If ActiveSheet.Cells(8, i) <= ActiveSheet.Cells(23, 13) Then
ActiveSheet.Cells(M, 9) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(7, i))/30 * 100
Else
ActiveSheet.Cells(M, 9) = (ActiveSheet.Cells(23, 13) - ActiveSheet.Cells(7, i))/30 * 100
ActiveSheet.Cells(M, 10) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(23, 13))/30 * 100
End If
If ActiveSheet.Cells(7, i) >= ActiveSheet.Cells(23, 14) Then
If ActiveSheet.Cells(8, i) <= ActiveSheet.Cells(23, 15) Then
ActiveSheet.Cells(M, 10) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(7, i))/30 * 100
Else
ActiveSheet.Cells(M, 10) = (ActiveSheet.Cells(23, 15) - ActiveSheet.Cells(7, i))/30 * 100
ActiveSheet.Cells(M, 11) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(23, 15))/30 * 100
End If
If ActiveSheet.Cells(7, i) >= ActiveSheet.Cells(23, 16) Then
If ActiveSheet.Cells(8, i) <= ActiveSheet.Cells(23, 17) Then
ActiveSheet.Cells(M, 11) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(7, i))/30 * 100
Else
ActiveSheet.Cells(M, 11) = (ActiveSheet.Cells(23, 17) - ActiveSheet.Cells(7, i))/30 * 100
ActiveSheet.Cells(M, 12) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(23, 17))/30 * 100
End If
If ActiveSheet.Cells(7, i) >= ActiveSheet.Cells(23, 18) Then
If ActiveSheet.Cells(8, i) <= ActiveSheet.Cells(23, 19) Then
ActiveSheet.Cells(M, 12) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(7, i))/30 * 100
Else
ActiveSheet.Cells(M, 12) = (ActiveSheet.Cells(23, 19) - ActiveSheet.Cells(7, i))/30 * 100
ActiveSheet.Cells(M, 13) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(23, 19))/30 * 100
End If
If ActiveSheet.Cells(7, i) >= ActiveSheet.Cells(23, 20) Then
If ActiveSheet.Cells(8, i) <= ActiveSheet.Cells(23, 21) Then
ActiveSheet.Cells(M, 13) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(7, i))/30 * 100
Else
ActiveSheet.Cells(M, 13) = (ActiveSheet.Cells(23, 21) - ActiveSheet.Cells(7, i))/30 * 100
ActiveSheet.Cells(M, 14) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(23, 21))/30 * 100
End If
If ActiveSheet.Cells(7, i) >= ActiveSheet.Cells(23, 22) Then
If ActiveSheet.Cells(8, i) <= ActiveSheet.Cells(23, 23) Then
ActiveSheet.Cells(M, 14) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(7, i))/30 * 100
Else
ActiveSheet.Cells(M, 14) = (ActiveSheet.Cells(23, 23) - ActiveSheet.Cells(7, i))/30 * 100
ActiveSheet.Cells(M, 15) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(23, 23))/30 * 100
End If
If ActiveSheet.Cells(7, i) >= ActiveSheet.Cells(23, 24) Then
If ActiveSheet.Cells(8, i) <= ActiveSheet.Cells(23, 25) Then
ActiveSheet.Cells(M, 15) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(7, i))/30 * 100
Else
ActiveSheet.Cells(M, 15) = (ActiveSheet.Cells(23, 25) - ActiveSheet.Cells(7, i))/30 * 100
ActiveSheet.Cells(M, 16) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(23, 25))/30 * 100
End If
If ActiveSheet.Cells(7, i) >= ActiveSheet.Cells(23, 26) Then
If ActiveSheet.Cells(8, i) <= ActiveSheet.Cells(23, 27) Then
ActiveSheet.Cells(M, 16) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(7, i))/30 * 100
Else
ActiveSheet.Cells(M, 16) = (ActiveSheet.Cells(23, 27) - ActiveSheet.Cells(7, i))/30 * 100
ActiveSheet.Cells(M, 17) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(23, 27))/30 * 100
End If
If ActiveSheet.Cells(7, i) >= ActiveSheet.Cells(23, 28) Then
If ActiveSheet.Cells(8, i) <= ActiveSheet.Cells(23, 29) Then
ActiveSheet.Cells(M, 17) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(7, i))/30 * 100
Else
ActiveSheet.Cells(M, 17) = (ActiveSheet.Cells(23, 29) - ActiveSheet.Cells(7, i))/30 * 100
ActiveSheet.Cells(M, 18) = (ActiveSheet.Cells(8, i) - ActiveSheet.Cells(23, 29))/30 * 100
End If
M = M + 1
Next i
可能是一个重复:https://stackoverflow.com/q/29021377/1531971(但是你应该表明您做了一些研究对这个非常普遍的问题) – jdv
为什么你使用'ActiveSheet。 Cells(8,i) - ActiveSheet.Cells(8,i)'?只是放在'0' – jsotola
如果有人在代码执行时更改为另一个工作表,会发生什么情况? – jsotola