+ Reply to Thread
Results 1 to 4 of 4

difficulty with "for" loop

  1. #1
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    difficulty with "for" loop

    Hello. I'm learning about for loops. The first example below I understand but I'm confused about the second. Is it just incrementing throug the code? If so, could you just put "imynumber2" without the +1 after it?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: difficulty with "for" loop

    I think you need to recognize the distinction between 2 different variables iMyNumber and iMyNumber2. To help facilitate this, review this very similar code:

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Re: difficulty with "for" loop

    Hmm. I understand the two variables, but I don't understand why you can put "imynumber" in the first example and it will add 1 each time but it won't do the same if I put "imynumber2" (without the +1).

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: difficulty with "for" loop

    I don't understand why you can put "imynumber" in the first example and it will add 1 each time
    The first one doesn't add anything. The first one is actually flawed code that will error. What you are thinking though is that it just keeps replacing the value so at the end of the loop "iMyNumber" is equal to the last number in the loop (in this case 100). Hence the point of the addition. To fix the first code it would require something like this:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  2. Replies: 2
    Last Post: 09-26-2013, 12:17 PM
  3. [SOLVED] Difficulty breaking link possibly caused by "Name" function.
    By navarreman1 in forum Excel General
    Replies: 1
    Last Post: 09-11-2013, 10:26 AM
  4. Having difficulty with VB on a button "Run-time error 1004"
    By andyaf in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-01-2013, 02:34 AM
  5. [SOLVED] Loop to check for "yes" then copy the IDs with "yes" and paste to other workbook
    By Hallet in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-11-2012, 12:41 PM

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