excel VBA溢出错误,当它不应该 [英] excel VBA Overflow error when it shouldn't

查看:111
本文介绍了excel VBA溢出错误,当它不应该的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sub TestFunction()
     Dim var As Double
     var = 25 * 24 * 23 * 22 * 21 * 20
End Sub

我收到此vba操作的溢出错误.当我在具有功能的单元中运行它时,我得到127,512,000

这可能是什么错误?这应该远低于此数据类型的大小限制吗?

解决方案

VBA烦人地将第一个术语转换为Integer,因为在您的情况下,它足够小.

修改此行,将其显式转换为double:

var = CDbl(25) * 24 * 23 * 22 * 21 * 20

Sub TestFunction()
     Dim var As Double
     var = 25 * 24 * 23 * 22 * 21 * 20
End Sub

I am receiving an overflow error for this vba operation. when i run it in a cell with functions i get 127,512,000

what could possibly be an error for this? this should be well below the size limit for this data type right?

解决方案

VBA annoyingly converts the first term to an Integer because in your case, it is small enough.

Amend this line, that it is converted explicitly to a double:

var = CDbl(25) * 24 * 23 * 22 * 21 * 20

这篇关于excel VBA溢出错误,当它不应该的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆