Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Nov 2001
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Step Value in a For Loop (Excel Sr-2A)

    Is it possible to use a decimal number for the Step value when creating a For...Next loop? Like So:

    For i = Start To End Step 0.5

    'Stuff

    Next i

    Thanks,
    Howard

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Step Value in a For Loop (Excel Sr-2A)

    Hi,
    Yes is the simple answer. Just make sure you don't declare i as an integer variable!
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    New Lounger
    Join Date
    Nov 2001
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Step Value in a For Loop (Excel Sr-2A)

    Rory,

    Thanks. This dawned on me right after I hit "Post It". I had 'i' declared as Long and had forgotten that meant "long INTEGER". Thanks again.

    Howard

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Step Value in a For Loop (Excel Sr-2A)

    Yes, BUT, one must take care that you get what you want.

    Adding floating point numbers is not as precise as integers so you might not ever use the upper bound of the index.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •