Need to insert a row every time I get a text change in column c

art69

New Member
Joined
Feb 27, 2015
Messages
6
Column C as a code the same code may be in 5 to 50 rows before it changes I need to insert a row between the change and copy the columns A,C & F from the lower row on to the newly created row. This file as over 100,000 rows to go through.

Any help would be great.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi,
This is a quick 'n dirty solution that I think does what you want. It assumes the first row of data is row 2.

Code:
Sub InsRows()

Dim iLstRow, i As Integer

iLstRow = Cells(Cells.Rows.Count, 3).End(xlUp).Row + 1
i = 3
Do While i < iLstRow
    If Cells(i, 3) <> Cells(i - 1, 3) Then
        Rows(i).Insert xlShiftDown
        Cells(i + 1, 1).Copy
        Cells(i, 1).PasteSpecial xlPasteAll
        Cells(i + 1, 3).Copy
        Cells(i, 3).PasteSpecial xlPasteAll
        Cells(i + 1, 6).Copy
        Cells(i, 6).PasteSpecial xlPasteAll
        Application.CutCopyMode = False
        i = i + 1
        iLstRow = iLstRow + 1
    End If
    i = i + 1
Loop

End Sub
 
Upvote 0
Hi,
This is a quick 'n dirty solution that I think does what you want. It assumes the first row of data is row 2.

Code:
Sub InsRows()

Dim iLstRow, i As Integer

iLstRow = Cells(Cells.Rows.Count, 3).End(xlUp).Row + 1
i = 3
Do While i < iLstRow
    If Cells(i, 3) <> Cells(i - 1, 3) Then
        Rows(i).Insert xlShiftDown
        Cells(i + 1, 1).Copy
        Cells(i, 1).PasteSpecial xlPasteAll
        Cells(i + 1, 3).Copy
        Cells(i, 3).PasteSpecial xlPasteAll
        Cells(i + 1, 6).Copy
        Cells(i, 6).PasteSpecial xlPasteAll
        Application.CutCopyMode = False
        i = i + 1
        iLstRow = iLstRow + 1
    End If
    i = i + 1
Loop

End Sub



Perfect helped me out big style thanks
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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