Copy Duplicate and Remove/Update Original Text

DaleKeel

Board Regular
Joined
Sep 11, 2019
Messages
56
Office Version
  1. 2013
Platform
  1. Windows
For each row where there is text in column E, copy the entire row and insert it below the original row. Then remove the text in column E from the row that was copied.
 

Attachments

  • excelM.jpg
    excelM.jpg
    116.3 KB · Views: 19

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try this code:
VBA Code:
Sub MyCopy()

    Dim lr As Long
    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Find last row in column E with data
    lr = Cells(Rows.Count, "E").End(xlUp).Row
    
'   If there are any values in column E, loop through column E backwards, from last row to first
    If lr > 2 Then
        For r = lr To 2 Step -1
'           See if anything in column E
            If Cells(r, "E") <> "" Then
'               Insert blank row below
                Rows(r + 1).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
'               Copy value from row to new row
                Rows(r).Copy Rows(r + 1)
'               Clear value from column E on current row
                Cells(r, "E").ClearContents
            End If
        Next r
    End If
        
    Application.ScreenUpdating = True

End Sub
 
Upvote 0
Solution
Try this code:
VBA Code:
Sub MyCopy()

    Dim lr As Long
    Dim r As Long
   
    Application.ScreenUpdating = False
   
'   Find last row in column E with data
    lr = Cells(Rows.Count, "E").End(xlUp).Row
   
'   If there are any values in column E, loop through column E backwards, from last row to first
    If lr > 2 Then
        For r = lr To 2 Step -1
'           See if anything in column E
            If Cells(r, "E") <> "" Then
'               Insert blank row below
                Rows(r + 1).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
'               Copy value from row to new row
                Rows(r).Copy Rows(r + 1)
'               Clear value from column E on current row
                Cells(r, "E").ClearContents
            End If
        Next r
    End If
       
    Application.ScreenUpdating = True

End Sub
This Worked. Thank you for your time. We worked on this for several weeks off and on but just could not get it right.
 
Upvote 0
You are welcome.

I put documentation in my code to try to explain/show what each step does.
Hope that is helpful.
 
Upvote 0

Forum statistics

Threads
1,224,735
Messages
6,180,638
Members
452,992
Latest member
TokugawaIesuma

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