Overflow when calculating a const in VBA

calendar_today Asked Nov 4, 2008
thumb_up 13 upvotes
history Updated April 16, 2026

Question posted 2008 · +10 upvotes

This declaration causes an overflow in VBA:

Const OVERFLOWS As Long = 10 * 60 * 60

whereas setting the value directly is fine:

Const COMPILES_OK As Long = 36000

How do you persuade VBA to treat literal integers as longs?

Thanks

Accepted answer +13 upvotes

Add the long suffix & to at least one number:

Const OVERFLOWS As Long = 10& * 60 * 60

Note that using the CLNG function to convert the values to long will not work, because VBA does not allow assigning the return value of a function to a constant.

Top vba Q&A (6)

+13 upvotes ranks this answer #32 out of 81 vba solutions on this site .
vba