PDA

View Full Version : As Integer datatype allows fractions



Jennifer
04-14-2013, 11:27 PM
I have a function defined like this:
Function Test(p1 as Integer) as Integer
test = p1 + 1
End Function
If it is called from a worksheet and passed a non-integer (=test(5.5)), it happily rounds it to 6 and returns 7. I was expecting a #Value error.

Can I get VBA to reject non-integer data if I declare the parameter as “Integer”?

If not, do I have to test every parameter inside the function to make sure it’s the right type? I thought that was what the declaration was for.

Puzzled...

Aflatoon
04-15-2013, 01:22 AM
Crossposted here (http://www.mrexcel.com/forum/excel-questions/697065-integer-datatype-allows-fractions.html).