首页 > 解决方案 > 运行时错误 - VBA 溢出 - 零除以零

问题描述

我在编写用于计算 % 费用的代码时遇到了一些问题。每当代码到达 H 和 M 列中的值为零的行时,我都会收到运行时错误 6。

下面是我的数据示例

H 列 M栏 N 列
5230170.94 3921.5 0.90%
20951143.9 12225.89 0.70%
0 0

下面是我的代码


Dim Main As Worksheet
Dim AUMLR, x  As Long

Set Main = ActiveSheet

AUMLR = Main.Range("A" & Rows.Count).End(xlUp).Row


    For x = 2 To AUMLR
    
        Main.Range("N" & x).Value = Main.Range("M" & x).Value / Main.Range("H" & x).Value * 12
    
    
    Next x


End Sub

标签: vbaruntime-error

解决方案


推荐阅读