Hey all,
Ive found some code on a forum elsewhere and tried to retrofit it solve a problem im facing with formatting.
I need to insert a certain amount of blank rows based on a value. I.E: If the value is 3, i need to insert 3 blank rows below this cell. The code ive found works nicely, but when it gets to 0 it doesnt work. Can anyone cast your eye over it and let me know if you find anything that may help.
Current Code:
Input:
<tbody>
</tbody>
Desired output:
<tbody>
</tbody>
Ive found some code on a forum elsewhere and tried to retrofit it solve a problem im facing with formatting.
I need to insert a certain amount of blank rows based on a value. I.E: If the value is 3, i need to insert 3 blank rows below this cell. The code ive found works nicely, but when it gets to 0 it doesnt work. Can anyone cast your eye over it and let me know if you find anything that may help.
Current Code:
Sub InsertRowsIf()
Dim lr As Long, R As Range, i As Long
lr = Range("C" & Rows.Count).End(xlUp).Row
Set R = Range("C1", "C" & lr)
Application.ScreenUpdating = False
For i = R.Rows.Count To 1 Step -1
If IsNumeric(R.Cells(i, 1).Value) And Not IsEmpty(R.Cells(i, 1)) Then
R.Cells(i, 1).Offset(1, 0).Resize(R.Cells(i, 1).Value).EntireRow.Insert
End If
Next
End Sub
Input:
Day/Night Shift | Date Code | Value |
Day | 1/1/2018 | 0 |
Day | 1/1/2018 | 1 |
Night | 1/1/2018 | 0 |
Night | 1/1/2018 | 0 |
Night | 1/1/2018 | 0 |
Day | 1/2/2018 | 2 |
Night | 1/2/2018 | 0 |
Night | 1/2/2018 | 1 |
Day | 1/3/2018 | 3 |
Night | 1/3/2018 | 3 |
<tbody>
</tbody>
Desired output:
Day/Night Shift | Date Code | Value |
Day | 1/1/2018 | 0 |
Day | 1/1/2018 | 1 |
Night | 1/1/2018 | 0 |
Night | 1/1/2018 | 0 |
Night | 1/1/2018 | 0 |
Day | 1/2/2018 | 2 |
Night | 1/2/2018 | 0 |
Night | 1/2/2018 | 1 |
Day | 1/3/2018 | 2 |
Night | 1/3/2018 | 2 |
<tbody>
</tbody>