+ Reply to Thread
Results 1 to 3 of 3

Weird counter question

  1. #1
    Registered User
    Join Date
    02-18-2007
    Location
    Manila / Philippines
    Posts
    42

    Weird counter question

    Hi,

    I have the following loop:

    For counter = 1 To Worksheets.Count - 1 Step 0.5

    Worksheets(counter).Activate
    counter = counter + 1
    Call results
    Next


    In this case worksheets(counter) has the value 22

    However, it only works if I set it to step 0.5.

    If I use step 1 the the counter actually counts 2 and is jumping from sheets 22 to 20-18-16 etc.

    Any idea why this is the case?

  2. #2
    Forum Contributor
    Join Date
    12-12-2005
    Posts
    667
    You are incrementing the Counter twice. Here is the corrected code:
    For counter = 1 To Worksheets.Count - 1 Step 1
    Worksheets(counter).Activate
    Call Results
    Next
    Best regards,

    Ray

  3. #3
    Registered User
    Join Date
    02-18-2007
    Location
    Manila / Philippines
    Posts
    42
    Many thanks for that!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1