Consulting

Results 1 to 5 of 5

Thread: Array Step by 50 - Loop Incremental

  1. #1
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location

    Array Step by 50 - Loop Incremental

    folks good day,

    is there a way to make another shortcut loop to go wth my array

    as you can see

    i would like to step by 50

    so i did the multiplication


    Dim n: n = 50                
        
    oDestination = Array("A1", "A" & n, "A" & 2 * n, "A" & 3 * n, "A" & 4 * n, "A" & 5 * n, "A" & 6 * n, "A" & 7 * n, "A" & 8 * n, "A" & 9 * n)
    but it does look very confusing to the layman

    with my A's and n's

    so the result is actually meant to be this in the array ("A1","A50",A100,A150....")

    these are my cell ranges
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Try this

    A1 requires some special handling



    Option Explicit
    
    Sub BuildArray()
        Dim i As Long
        Dim s As String
        Dim oDestination As Variant
        
        s = "A1;"
        
        For i = 50 To 450 Step 50
            s = s & "A" & i & ";"
        Next i
        s = Left(s, Len(s) - 1)
     
        oDestination = Split(s, ";")
        Stop
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    Well all i can say Paul
    is you are some sort of genuis.

    And you may be able to read minds too, i forgot to mention the partner array but you knew somehow.

    I had 2 arrays

    this one being the destination with the 50 increment and another one.

    Well this line

    oDestination = Array("A1", "A" & n, "A" & 2 * n, "A" & 3 * n, "A" & 4 * n, "A" & 5 * n, "A" & 6 * n, "A" & 7 * n, "A" & 8 * n, "A" & 9 * n, "A" & 10 * n, "A" & 11 * n) 'n*2 , n*3

    was only meant to be small but it got bigger as i had more ranges, now dont ask me how these things happen

    Suffice to say i am very happy with this new step loop it will come in very handy so i dont have to type all those multiplications, and i spent half a day not understing a nested while loop so i gave up

    well thank you very much Paul

    and a cracking friday and great weekend
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Or

    Sub M_snb()
       Range(Join([transpose("A"&50*row(1:9))], ",")).Interior.ColorIndex = 3
    End Sub

  5. #5
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    Thank you SNB,

    i will play about with this as well
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


Posting Permissions

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