I want the row I copy into new sheet to stay in original sheet as well (script)

runeroan

New Member
Joined
Nov 11, 2017
Messages
16
Hi, this script copy the entire row into another sheet based on text value in a cell. Copy works fine.
However it also delete the row copied from original sheet, and I need it to stay! I need the row to stay and be copied, not copied and deleted. How can I get rid of line "Cell.EntireRow.Delete" as this does the delete? If I remove the line I get error. Please help. Thanks.


Sub Kopiere_til_I_produksjon()
Lastrow = Worksheets("Hertz").UsedRange.Rows.Count
lastrow2 = Worksheets("I_produksjon").UsedRange.Rows.Count
If lastrow2 = 1 Then
lastrow2 = 0
Else
End If
Do While Application.WorksheetFunction.CountIf(Range("D:D"), "Innlevert") > 0
Set Check = Range("D1:D" & Lastrow)
For Each Cell In Check
If Cell = "Innlevert" Then
Cell.EntireRow.Copy Destination:=Worksheets("I_produksjon").Range("A" & lastrow2 + 1)
Cell.EntireRow.Delete
lastrow2 = lastrow2 + 1
Else:
End If
Next
Loop
End Sub
 
Put this script in sheet named "Hertz"

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
If Target.Column = 4 And Target.Value = "Innlevert" Then
Application.EnableEvents = False
If Target.Interior.ColorIndex = 4 Then MsgBox "That row has already been copied over": Exit Sub
Dim Lastrow As Long
Lastrow = Sheets("I_produksjon").Cells(Rows.Count, "D").End(xlUp).Row + 1
Rows(Target.Row).Copy Sheets("I_produksjon").Rows(Lastrow)
Sheets("I_produksjon").Cells(Lastrow, 45).Value = Target.Row
Target.Interior.ColorIndex = 4
End If
Application.EnableEvents = True
End Sub


Put this script in sheet named "I_produksjon"


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
If Target.Column = 4 And Target.Value = "Levert" Then
Application.EnableEvents = False
Dim ans As Long
ans = Cells(Target.Row, 45).Value
Sheets("Hertz").Cells(ans, 4).Value = "Levert"
Sheets("Hertz").Cells(ans, 4).Interior.ColorIndex = xlNone
Rows(Target.Row).EntireRow.Delete
End If
Application.EnableEvents = True
End Sub
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi, could you make this happen?

In sheet "RES" I have a coloumn F named "Levert"
I would like to move entire row with existing fomulas to sheet "FAKT"
The moved row should be removed from sheet "RES" when moved to "sheet "FAKT"
The row needs to be placed on next availiable row in sheet "FAKT"

Can you make it happen?
 
Upvote 0
I do not understand what you want.

You said:
In sheet "RES" I have a coloumn F named "Levert"

Why do I care what the name is of column "F"

Do you mean if any row has the value "Levert" in column "F" then Copy this row to sheet named "FAKT" ?
 
Upvote 0
Thanks for feedback.

Yes, if any row has the value "Levert" in column "F" then Copy this row to sheet named "FAKT".
 
Upvote 0
Try this:
Code:
Sub Filter_Me()
'Modified 1-4-2018 7:05 AM EST
Dim Lastrow As Long
Lastrow = Sheets("FAKT").Cells(Rows.Count, "F").End(xlUp).Row + 1
Sheets("RES").Activate
    With ActiveSheet.Range("F1:F" & Cells(Rows.Count, "F").End(xlUp).Row)
        .AutoFilter 1, "Levert"
        .Offset(1).SpecialCells(12).EntireRow.Copy Sheets("FAKT").Range("A" & Lastrow)
        .Offset(1).SpecialCells(12).EntireRow.Delete
        .AutoFilter
    End With
Sheets("RES").Rows(1).Copy Sheets("FAKT").Rows(1)
End Sub
 
Upvote 0
Try this:
Code:
Sub Filter_Me()
'Modified 1-4-2018 9:45 AM EST
Dim Lastrow As Long
Lastrow = Sheets("FAKT").Cells(Rows.Count, "F").End(xlUp).Row + 1
Sheets("RES").Activate
    With ActiveSheet.Range("F1:F" & Cells(Rows.Count, "F").End(xlUp).Row)
        .AutoFilter 1, "Levert"
        .Offset(1).SpecialCells(12).EntireRow.Copy
        Sheets("FAKT").Range("A" & Lastrow).PasteSpecial Paste:=xlPasteFormulas
        Sheets("FAKT").Range("A" & Lastrow).PasteSpecial Paste:=xlPasteFormats
        .Offset(1).SpecialCells(12).EntireRow.Delete
        .AutoFilter
    End With
Sheets("RES").Rows(1).Copy Sheets("FAKT").Rows(1)
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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