+ Reply to Thread
Results 1 to 7 of 7

For Loop Iteration ?

  1. #1
    Registered User
    Join Date
    09-14-2017
    Location
    Orlando
    MS-Off Ver
    2013
    Posts
    14

    For Loop Iteration ?

    Hello there,

    I'm trying to initialize a bunch of variables at once, is there a way to do this with a For Loop? I know in some languages I could do it as the following:
    PHP Code: 
      for (int X 151X++) {
        
    Msgbox(X)
      } 
    I have a set of 50 points, lets say A1:A50 and I'm trying to make each cell a variable.

    A1=10
    A2=11
    A3=12
    Etc.

    What I would like to do next is then add 10 to each of those variables numerous times (user input). So lets say user inputs 3.
    I would like to list the following in new cells, for instance the second run of A1 would start posting at A:51

    A1=10
    A2=11
    A3=12
    Etc.

    Then
    A1=20
    A2=21
    A3=22
    Etc.

    A1=30
    A2=31
    A3=32
    Etc.



    I've been mulling over this the past few days and I feel my code is super bloated and I know there is a better way of doing this.



    TIA!
    Last edited by distantkitty; 10-09-2017 at 07:17 AM.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: For Loop Iteration ?

    Slightly confused about your requirement

    What is the purpose of showing 10,20 & 30 in A1 cell?


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: For Loop Iteration ?

    Here are some of the equivalent loops in VBA. Do not use dollar sign to indicate a variable in VBA. If you use a For Loop in VBA, you do not need to change the loop variable.

    Please Login or Register  to view this content.
    Last edited by AB33; 10-09-2017 at 07:05 AM.

  4. #4
    Registered User
    Join Date
    09-14-2017
    Location
    Orlando
    MS-Off Ver
    2013
    Posts
    14

    Re: For Loop Iteration ?

    Quote Originally Posted by :) Sixthsense :) View Post
    Slightly confused about your requirement

    What is the purpose of showing 10,20 & 30 in A1 cell?
    Sorry, i didn't explain that well. When the second run of A1:A50 starts, I'd start it at A:51 and third run would start at A:101 and so on.

    Thanks!

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: For Loop Iteration ?

    Does this help?

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-14-2017
    Location
    Orlando
    MS-Off Ver
    2013
    Posts
    14

    Re: For Loop Iteration ?

    Quote Originally Posted by JOHN H. DAVIS View Post
    Does this help?

    Please Login or Register  to view this content.
    I guess I'm just trying to initialize 50 variables quickly versus manually defining 50 variables.
    IE:
    A1 = Var1
    A2 = Var2
    A3 = Var3
    ---
    A50 = Var50

    Thanks!

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: For Loop Iteration ?

    It is not clear to me exactly what you are trying to do here. As a guess, it sounds like you are seeking to understand the concept of arrays in VBA (similar to the same concept in other programming languages). Perhaps something like this: https://powerspreadsheets.com/excel-vba-array/
    or this: http://www.excel-easy.com/vba/array.html
    will get you started. For initializing an array of 50 elements, something like
    Please Login or Register  to view this content.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ 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 move to next iteration of a Do Until loop
    By DannyJ in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-21-2017, 08:10 AM
  2. [SOLVED] My loop is missing last iteration
    By elmnas in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-22-2016, 06:46 PM
  3. [SOLVED] Go to next loop iteration if current loop has error
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-03-2016, 09:54 PM
  4. VBA - How to continue inner loop while going to next iteration of outer loop?
    By alviniac in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-14-2015, 11:21 PM
  5. jump to xth iteration of for next loop
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-25-2015, 12:07 PM
  6. [SOLVED] Last Iteration of Loop?
    By saintplay in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-17-2015, 08:19 PM
  7. [SOLVED] Loop fails on 2nd iteration
    By capson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-14-2014, 01:38 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