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 =O

    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

  • 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!