Using paste special to copy rows into new sheet VBA

Georgia101

New Member
Joined
Jun 4, 2020
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I am new to VBA and have successfully used the below code to copy a row based on unique identifier ,column 15 as I have multiple duplicate data. The row is copied into another worksheet “flag list” at the bottom based on having Y in the unique column.

However I cannot figure out how to modify to ensure it is paste special, so that when I update the original rows in the workbook the copied rows on flag list autoupdate to reflect changes.

I also have a part to my code so that when a row is changed to N it deleted this row from the flag list.

Any help at all with modifying to paste linkcells (paste special) would be much appreciated.

Many thanks,

Georgia

the code :

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)



If Target.Column = 12 Then

Set destinationSheet = ThisWorkbook.Sheets("FLAG LIST")

uniqueColumnlookup = 15

vNew = Target.Value

Application.EnableEvents = False

Application.Undo

vOld = Target.Value

Target.Value = vNew

Application.EnableEvents = True

If vNew <> vOld Then

lastrow = destinationSheet.Range("A" & Rows.Count).End(xlUp).Row

If vNew = "Y" Or vNew = "y" Then

lastrow = destinationSheet.Range("A" & Rows.Count).End(xlUp).Row

Sh.Cells(Target.Row, Target.Column).EntireRow.Copy Destination:=destinationSheet.Cells(lastrow + 1, 1)

End If

If vNew = "N" Or vNew = "n" Then

For i = 1 To lastrow

If destinationSheet.Cells(i, uniqueColumnlookup).Value = Sh.Cells(Target.Row, uniqueColumnlookup).Value Then

destinationSheet.Rows(i).EntireRow.Delete

End If

Next

End If

End If



End If

End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Maybe..

VBA Code:
    If LCase(vNew) = "y" Then

        lastrow = destinationSheet.Range("A" & Rows.Count).End(xlUp).Row

        Sh.Cells(Target.Row, Target.Column).EntireRow.Copy
        destinationSheet.Cells(lastrow + 1, 1).PasteSpecial xlValues
        Application.CutCopyMode = False
    End If
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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