我遇到了循环溢出的问题。这是我的代码:
Private Sub DivideKPI()
Dim FRow As Long
Dim lrow As Long
Dim PRow As Long
Dim CurrentSheet As Worksheet
Set CurrentSheet = Excel.ActiveSheet
FRow = CurrentSheet.UsedRange.Cells(1).Row
lrow = CurrentSheet.UsedRange.Rows(CurrentSheet.UsedRange.Rows.count).Row
For PRow = lrow To 2 Step -1
CurrentSheet.Cells(PRow, "AO").Value = Round(((CurrentSheet.Cells(PRow, "AK").Value) / (CurrentSheet.Cells(PRow, "AM").Value)), 2)
Next PRow
End Sub
如果我把' PROW'手动而不是循环,可以产生结果。但是我需要循环这个因素,因为有这么多数据。怎么做到这一点?我已经使用了CLng但也溢出了。 谢谢!
*示例数据
AK AM
25.35 72
224.92 24
答案 0 :(得分:0)
我不相信PRow
可能是你的问题。尝试:
For PRow = lrow To 2 Step -1
CurrentSheet.Cells(PRow, "AO").Value2 = Round(((CurrentSheet.Cells(PRow, "AK").Value2) / (CurrentSheet.Cells(PRow, "AM").Value2)), 2)
Next PRow