Code stops when it hits a blank row -- I think
Hi Craig,
Thanks for helping me. I'm pulling my hair out on this one.
I want to insert the following rows under the following conditions:
1.) If cell (irow, 12) >0
2.) Skip blank rows
then continue to the next column and do the same thing,
3.) If cell(irow, 13) >0
4.) Skip blank rows (HERE IS WHERE I THINK IT IS MESSING UP). When the code reaches a blank row from the previous operation under column #12, it stops.
** I have 5 columns that I want it to run through.
1.) Insert one row (column 12....I changed it from column 25)
2.) Insert 2 rows (column 13 when it reaches a number >0)
3.) Insert 3 rows (column 14 ...etc.)
4.) Insert 4 rows (column 15 etc.)
I tried to put in the following code by I'm stuck:
For i = 3 To 50000
If Cells(i, 13) = "" Then
GoTo NextRec
End If
NextRec:
Next i
Anyway, here is what I am trying to do. I really appreciate your help.
Sub InsertRows()
iRow = 3
Do Until Sheets("Heijunka Box Prep").Cells(iRow, 12) = ""
If Sheets("Heijunka Box Prep").Cells(iRow, 12) > 0 Then 'Greater than 0
Sheets("Heijunka Box Prep").Rows(iRow + 1).Insert 'Insert a whole row
iRow = iRow + 2 'ie there is now another row to skip
Else
iRow = iRow + 1
End If
Loop
iRow = 3
Do Until Sheets("Heijunka Box Prep").Cells(iRow, 13) = ""
If Sheets("Heijunka Box Prep").Cells(iRow, 13) > 0 Then 'Greater than 0
Sheets("Heijunka Box Prep").Rows(iRow + 1).Insert 'Insert a whole row
Sheets("Heijunka Box Prep").Rows(iRow + 1).Insert 'Insert a whole row
iRow = iRow + 2 'ie there is now another row to skip
Else
iRow = iRow + 1
End If
Loop
iRow = 3
Do Until Sheets("Heijunka Box Prep").Cells(iRow, 14) = ""
If Sheets("Heijunka Box Prep").Cells(iRow, 14) > 0 Then 'Greater than 0
Sheets("Heijunka Box Prep").Rows(iRow + 1).Insert 'Insert a whole row
Sheets("Heijunka Box Prep").Rows(iRow + 1).Insert 'Insert a whole row
Sheets("Heijunka Box Prep").Rows(iRow + 1).Insert 'Insert a whole row
iRow = iRow + 2 'ie there is now another row to skip
Else
iRow = iRow + 1
End If
Loop
iRow = 3
Do Until Sheets("Heijunka Box Prep").Cells(iRow, 15) = ""
If Sheets("Heijunka Box Prep").Cells(iRow, 15) > 0 Then 'Greater than 0
Sheets("Heijunka Box Prep").Rows(iRow + 1).Insert 'Insert a whole row
Sheets("Heijunka Box Prep").Rows(iRow + 1).Insert 'Insert a whole row
Sheets("Heijunka Box Prep").Rows(iRow + 1).Insert 'Insert a whole row
Sheets("Heijunka Box Prep").Rows(iRow + 1).Insert 'Insert a whole row
iRow = iRow + 2 'ie there is now another row to skip
Else
iRow = iRow + 1
End If
Loop
iRow = 3
Do Until Sheets("Heijunka Box Prep").Cells(iRow, 16) = ""
If Sheets("Heijunka Box Prep").Cells(iRow, 16) > 0 Then 'Greater than 0
Sheets("Heijunka Box Prep").Rows(iRow + 1).Insert 'Insert a whole row
Sheets("Heijunka Box Prep").Rows(iRow + 1).Insert 'Insert a whole row
Sheets("Heijunka Box Prep").Rows(iRow + 1).Insert 'Insert a whole row
Sheets("Heijunka Box Prep").Rows(iRow + 1).Insert 'Insert a whole row
Sheets("Heijunka Box Prep").Rows(iRow + 1).Insert 'Insert a whole row
iRow = iRow + 2 'ie there is now another row to skip
Else
iRow = iRow + 1
End If
Loop
End Sub
Thanks,
Jim