Excel like a finance pro.
VBA · Variables
Data types
Long for whole numbers, Double for decimals, String for text, Boolean for True/False, Date, Variant for anything.
When to use it
Each variable has a type: Long for whole numbers, Double for decimals, String for text, Boolean for True/False, Date for dates and times, and Variant for anything. Picking the right type prevents overflow and conversion bugs.
The code
- Code
Dim count As Long Dim price As Double Dim ok As Boolean
Worked examples
Common types
Dim count As Long Dim price As Double Dim ok As Boolean → Whole number, decimal, flag
The three most used.
Why Long, not Integer
Dim n As Integer n = 40000 ' overflow error → Integer tops out at 32,767
Use Long instead.
Dates
Dim d As Date d = DateSerial(2025, 3, 15) → A real date
Date math works on it.
Worth knowing
- Use Long, not Integer. Integer overflows at 32,767.
- Long has no speed penalty over Integer on modern Excel.
- Currency holds money to four decimals without floating-point drift.
- Convert explicitly with CLng, CDbl, CStr rather than relying on implicit conversion.
Where it goes wrong
- Integer overflow at 32,767 is a runtime error 6.
- Doubles can show 0.1 + 0.2 as 0.30000000000000004; round for display.
Related
Learn the moves here — or let Wauvel run them on your numbers.
Meet your AI CFO →One CFO-grade Excel tip a week
A short, practical email for finance operators — functions, shortcuts, and the moves that save an afternoon. Free, unsubscribe anytime.