(Solved) – How to get nested loop to move to next set of data in VBA


I have a worksheet (CAT) where I’m trying to copy 15 rows of 8 columns of data into one row in the other worksheet (Transpose). I have multiple nested loops where I need one of my loops to move on to the next set of 15 rows in the CAT worksheet (rowIndex). Instead the code goes back to the first 2 to 16 rows and fills in the same 15 rows each time. I’ve tried multiple iterations of adding rowIndex = rowIndex 15, but this doesn’t seem to be doing anything. Can anyone help me with what I’m doing wrong?

    For rowTranspose = 2 To 3 'move down one row when first row is filled in Transpose sheet
       For colTranspose = 8 To 120 Step 8 'write data from columns 8 to 15 and rows 2 to 16 (colIndex, rowIndex) in columns 8 through 120 of Transpose sheet
           For rowIndex = 2 To 16 'loop through rows 2 through 16
               For colIndex = 8 To 15 'loop through columns 8 through 15
                    Transpose.Cells(rowTranspose, colTranspose) = CAT.Cells(rowIndex, colIndex) 'copy CAT worksheet values to rowTranspose and colTranspose values
                    colTranspose = colTranspose   1 'move the columns over so that the CAT info copies to the correct column
               Next colIndex
           Next rowIndex
       Next colTranspose
       rowIndex = rowIndex   15
    Next rowTranspose

Leave a Reply

Your email address will not be published. Required fields are marked *