Copy paste entire row below the cell that contain specific word

iamalvin

New Member
Joined
Sep 12, 2017
Messages
4
Good day to you all.
As the title implies, I would like to copy entire row and paste it at the SAME WORKSHEET below the cell that contain specific word. For example,
ABC
XXXXXXABCDEFG/123456YYYYY

<tbody>
</tbody>

I would like to change the above table to :
ABC
XXXXXXABCDEFG/123456YYYYY
XXXXXXABCDEFG/123456YYYYY

<tbody>
</tbody>

The specific text i meant was this symbol "/". So if column B contains 2 "/", then 2 additional row will be added below the original row.
I have a macro that could possibly do this but end up giving me an error. I would really appreciate if someone could point out where is the error.
Code:
Sub Insert_CopyPaste()


    Dim LastRow As Long, I As Long, txt As String
    txt = "/" 'set text to search
    With Sheets("Sheet9")


        LastRow = .Range("B6000").End(xlUp).Row
        Do While I <= LastRow


            If .Range("C" & I).Value = "/" Then


                .Range("a" & I).EntireRow.Copy
                .Range("a" & I + 1).EntireRow.Insert
                .Range("a" & I + 1).PasteSpecial xlPasteValues
        


            End If


            I = I + 1 'goto next row to check


        Loop
    End With
End Sub

Thank you!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try:
Code:
Sub InsertCopyPaste()

    Dim LR          As Long
    Dim LC          As Long
    Dim x           As Long
    Dim strCount    As Long
    
    LR = Cells(Rows.count, 1).End(xlUp).row
    LC = Cells(1, Columns.count).End(xlToLeft).column
    
    Application.ScreenUpdating = False
    
    For x = LR To 2 Step -1
        strCount = Len(Cells(x, 2).Value) - Len(Replace(Cells(x, 2).Value, "/", vbNullString))
        If strCount > 0 Then
            Cells(x + 1, 1).Resize(strCount, LC).EntireRow.Insert
            Cells(x, 1).Resize(strCount + 1, LC).FillDown
            strCount = 0
        End If
    Next x

    Application.ScreenUpdating = True

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,009
Messages
6,122,674
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top