Copy and paste above found row

silentwolf

Well-known Member
Joined
May 14, 2008
Messages
1,216
Office Version
  1. 2016
Hi guys,

I like to copy an entire row and paste that row above found row if condition is met.

this is what I got so far but how do I need to ad the paste line into that code?


Code:
Sub InsertCopiedRowAboveNumerberOne()
    Dim lngZeile As Long
    Dim lngZeileMax As Long
    
    With ActiveSheet
        lngZeileMax = .UsedRange.Rows.Count
        For lngZeile = lngZeileMax To 2 Step -1
            If .Cells(lngZeile, 7).Value = 1 Then
            
                .Cells.EntireRow.Copy
                
                .Rows(lngZeile).EntireRow.Insert
                
            End If
        Next lngZeile
    End With
End Sub

so i like to find the number 1 in column G and copy that row above that row.

Idealy I like to change the value of the call in column C to 156 and the rest of the row values should stay the same.

Many thanks for your help!!

Cheers Albert
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
@silentwolf

.Cells.EntireRow.Copy is trying to copy the whole sheet.

Maybe like....

Code:
Sub InsertCopiedRowAboveNumerberOne()    Dim lngZeile As Long
    Dim lngZeileMax As Long
Application.ScreenUpdating = False
    With ActiveSheet
        lngZeileMax = .UsedRange.Rows.Count
        For lngZeile = lngZeileMax To 2 Step -1
            If .Cells(lngZeile, 7).Value = 1 Then
            
            '*** Move line to here if both C cells to be 156
                .Cells(lngZeile, 7).EntireRow.Copy
                
                .Rows(lngZeile).EntireRow.Insert
                
                .Cells(lngZeile, 3) = 156  'Move if both cells to be 156***
                
                
            End If
        Next lngZeile
    End With
    
    Application.CutCopyMode = False
   Application.ScreenUpdating = True
 
End Sub

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,214,395
Messages
6,119,265
Members
448,881
Latest member
Faxgirl

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