Note that there are some explanatory texts on larger screens.

plurals
  1. PODual Loops in VBA
    text
    copied!<p>I am trying to run this loop where the indices in the loop change at the same time. </p> <pre><code>For i = 0 To 20 Step 5 For j = 0 To 5 Step 1 Range(ActiveCell, ActiveCell.Offset(5 + i, 0)).Copy Destination:=Cells(8, 12 + j) Next i Next j </code></pre> <p>I am trying to get the loop to do this</p> <pre><code>Range(ActiveCell, ActiveCell.Offset(5 + 0, 0)).Copy Destination:=Cells(8, 12 + 0) Range(ActiveCell, ActiveCell.Offset(5 + 5, 0)).Copy Destination:=Cells(8, 12 + 1) Range(ActiveCell, ActiveCell.Offset(5 + 10, 0)).Copy Destination:=Cells(8, 12 + 2) Range(ActiveCell, ActiveCell.Offset(5 + 15, 0)).Copy Destination:=Cells(8, 12 + 3) Range(ActiveCell, ActiveCell.Offset(5 + 20, 0)).Copy Destination:=Cells(8, 12 + 4) </code></pre> <p>The loop I have unfortuantly does this:</p> <pre><code>Range(ActiveCell, ActiveCell.Offset(5 + 0, 0)).Copy Destination:=Cells(8, 12 + 0) Range(ActiveCell, ActiveCell.Offset(5 + 5, 0)).Copy Destination:=Cells(8, 12 + 0) Range(ActiveCell, ActiveCell.Offset(5 + 10, 0)).Copy Destination:=Cells(8, 12 + 0) ... Range(ActiveCell, ActiveCell.Offset(5 + 0, 0)).Copy Destination:=Cells(8, 12 + 1) Range(ActiveCell, ActiveCell.Offset(5 + 5, 0)).Copy Destination:=Cells(8, 12 + 1) </code></pre> <p>I guess I can have a single loop such that: But that doesn't quite do it.</p> <pre><code>For i = 0 To 20 Step 5 Range(ActiveCell, ActiveCell.Offset(5 + i, 0)).Copy Destination:=Cells(8, 12 + j-4) Next j </code></pre> <p>Can anyone suggest any ideas for having a loop where the indicies are changing concurrently at the same time? Thank you!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload