gpt4 book ai didi

VBA 循环溢出

转载 作者:行者123 更新时间:2023-12-04 21:02:30 25 4
gpt4 key购买 nike

我有循环溢出的问题。这是我的代码:

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

关于VBA 循环溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33473498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com