Forum Discussion
khjhzw
Mar 10, 2022Copper Contributor
How to insert (or create) new rows under every row that meets a certain condition?
Hello, Thank you for reading my question. Could you please help me with this task? I have to do a repetitive task with a quite a large excel worksheet (or table). I am wondering if there is w...
- 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.
OliverScheurich
Mar 10, 2022Gold Contributor
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.
khjhzw
Mar 10, 2022Copper Contributor
Thank you so much for your help. It works! Fabulous. Wonderful!
Regards,
Kang
Regards,
Kang