VBA 循环溢出
VBA Loop Overflow
我遇到了循环溢出的问题。这是我的代码:
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
我认为 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
我遇到了循环溢出的问题。这是我的代码:
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
我认为 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