Sqr function stopping vba code (?!)

484 views Asked by At

Sorry for my stupid question, but I can´t understand just for it be so simple.

Excel 2010 stops running when I try the code below:

Sub Delay()

Dim j As Double
Dim i As Double
Dim k As Double

    For i = 1 To 1000000
        j = Sqr(i)
        k = 0
        Do While k < 1000000
            j = Sqr(k)
            k = k + 1
        Loop
    Next

End Sub

This sub does nothing, just spends time. So why excel is not responding?

VBA can´t be so weak. What am I losing?

Thanks.

1

There are 1 answers

0
ermagana On

What you're doing there is causing excel to go into a loop for 1,000,000 iterations. What you're trying to do is probably best answered by this post