VBA 循环溢出

标签 vba excel 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

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

相关文章:

vba - 使用 Excel VBA 将单个工作簿拆分为包含多个工作表的多个工作簿

excel - 如何在 Excel VBA 中将新形状添加到现有形状组?

iframe - 删除垂直滚动条,将水平滚动条保留在Chrome的iframe中

css - "overflow: hidden;"被 PC 上的 Chrome 忽略

vba - 在 Word VBA 中使用 Application.Run 传递参数

文本框中的VBA文本字符串限制

vba - CreatePivotTable() 上的奇怪/不稳定行为

vba - 签名未出现在 Excel 自动电子邮件中

vba - 当我添加具有相同代码的新 Sub 时 Excel 宏不起作用

css - 与溢出: hidden?相反这可能吗?