Loop steps abs > 1000 RRS feed

  • Question

  • Hello, I often write macros to simulate investments returns and I often need to use step values in my loops larger than 1000, but the macro do not run because of the step being > 1000, at least the debug highlights that row. If I change the values scale and downsize the step in a range abs 0 - 999 it works fine.

    How can I solve this problem? Is that a matter of syntax?

    Thanks in advance

    Tuesday, June 21, 2016 2:06 PM


All replies

  • Make sure that you declare the loop index as Long. For example, the following code works fine when I run it:

    Sub Test()
        Dim i As Long
        For i = 100000 To 400000 Step 15000
            Debug.Print i
        Next i
    End Sub

    Regards, Hans Vogelaar (

    Tuesday, June 21, 2016 2:30 PM
  • Out of curiosity, what variable type do you use for the loop counter?

    There is no variable that has it's upper limit as 1000.

    Best regards, George

    Tuesday, June 21, 2016 3:10 PM
  • Hi Nino76,

    I agree with suggestion given by the Hans Vogelaar MVP.

    set the datatype of variable as long and try to test it again If it solved your issue I would recommend you to mark the suggestion given by the Hans Vogelaar MVP as an Answer.

    if it not solves your issue then please try to share your code with our community so that we can try to test it on our side.



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, June 22, 2016 1:16 AM