Forum Discussion
How to insert (or create) new rows under every row that meets a certain condition?
- Mar 10, 2022
Sub insertrow() Dim i As Integer Dim j As Integer For i = 1 To 1000 j = InStr(1, Cells(i, 1), "chapter", vbTextCompare) If j = 1 Then Cells(i + 1, 1).EntireRow.Insert Cells(i + 2, 1).EntireRow.Insert Cells(i + 1, 2).Value = "word count" Cells(i + 2, 2).Value = "date started" i = i + 2 Else End If Next i End Sub
Maybe with these lines of code. Click the button in cell E1 in the attached file to start the macro.
Sub insertrow()
Dim i As Integer
Dim j As Integer
For i = 1 To 1000
j = InStr(1, Cells(i, 1), "chapter", vbTextCompare)
If j = 1 Then
Cells(i + 1, 1).EntireRow.Insert
Cells(i + 2, 1).EntireRow.Insert
Cells(i + 1, 2).Value = "word count"
Cells(i + 2, 2).Value = "date started"
i = i + 2
Else
End If
Next i
End Sub
Maybe with these lines of code. Click the button in cell E1 in the attached file to start the macro.
- mrgcavOct 20, 2023Copper Contributor
Similar to what I need.
https://techcommunity.microsoft.com/t5/excel/how-to-insert-or-create-new-rows-under-every-row-that-meets-a/m-p/3254132
I have an excel 2019 form with 10 rows and columns A-Z (26). Some files have less than 10 entries. Some files have more than 10 entries. All cells have a formula with in them.Column C is always an integer, Column D are Alphanumeric, Column G is Alphanumeric text. If that matters.
I do not know VBA but I Need a simple macro to add another row (row 11) when Cells 10C and 10D and 10G all have data. So by the time I fill in 10Z there is a row 11 and the cells in row 11 have a incremented formula.
This repeats so I will always have one more line than I need.
Basically if the last line starts gets three trigger cells, filled with any data, Add another line, filled with increment formulas based on the previous formulas above each respective cell.
Rows also have formatted boarders. New cells in the new row need the same format boarder as the row above.
Form will have a minimum of fixed 10 rows.
Could have up to another 100 conditional rows.
This would save on paper when the list is printed.
- khjhzwMar 10, 2022Copper ContributorThank you so much for your help. It works! Fabulous. Wonderful!
Regards,
Kang