# Bug in For ?!

• Hello,

Repeat this code, please, because I repeated it on two computers and it gave the same error!

The Combin function returns 210, but the For which should go up to this value, stops at 209

A1 = correct value, B1 = 209. Thanks.

Code
``````Sub Bug_()
Combin_ = WorksheetFunction.Combin(10, 4)
Range("A1") = Combin_

For Var_ = 1 To Combin_
Range("B1") = Var_
Next
End Sub``````
• It's not a bug in For. The Combin is actually returning a very small decimal fraction (if you add a

Code
``Msgbox  Combin_ - 210``

you will see it). If you declare the Combin_ variable as Long, you won't have the problem.

Rory
Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

• Exactly!

Do you know why he does this? After all, using the statistical formula Cn,p, the combination of 10 elements, 4 in 4, is exactly 210!

Thank you!

• No idea, in all honesty.

Rory
Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

## Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!