Forum Discussion

khjhzw's avatar
khjhzw
Copper Contributor
Mar 10, 2022
Solved

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...
  • OliverScheurich's avatar
    Mar 10, 2022

    khjhzw 

    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.

Resources