Copying cells into a new sheet without duplictaes

MIB

New Member
Joined
Jun 15, 2021
Messages
11
Office Version
  1. 365
  2. 2011
Platform
  1. Windows
I have never done VBA before, but found a code online to copy rows to a new sheet based on cell value. My problem is is that the source sheet is constantly being updated and every time I run teh macro it copies all teh rows all over again instead of just the newly inputted ones.
This is the code I am using. Is there any way to make it so it only transfers rows that are not already at the destination sheet?
Sub SHOESHOW()
'Updated by Extendoffice 2017/11/10
Dim xRg As Range
Dim xCell As Range
Dim I As Long
Dim J As Long
Dim K As Long
I = Worksheets("All Shipments").UsedRange.Rows.Count
J = Worksheets("Shoe Show").UsedRange.Rows.Count
If J = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("Shoe Show").UsedRange) = 0 Then J = 0
End If
Set xRg = Worksheets("All Shipments").Range("F1:F" & I)

Application.ScreenUpdating = False
For K = 1 To xRg.Count
If CStr(xRg(K).Value) Like "*SHOE SHOW*" Then
xRg(K).EntireRow.Copy Destination:=Worksheets("Shoe Show").Range("A" & J + 1)
J = J + 1
End If
Next
Application.ScreenUpdating = True
End Sub

Thanks!!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Welcome to the Board!

How exactly is new data being added to the sheet?
Is there any sort of date/time stamp to indicate when a new row is added?
Can we add a column to the "All Shipments" tab to track which rows have been copied over?
 
Upvote 0
Thanks for the welcome and the help!
As of right now, the rows are only being added based on the value in column F, which I guess is the problem. We can definitely add a column to "All Shipments" to keep track of which have been copied over. How would that work?
 
Upvote 0
Thanks for the welcome and the help!
As of right now, the rows are only being added based on the value in column F, which I guess is the problem. We can definitely add a column to "All Shipments" to keep track of which have been copied over. How would that work?
That may not be necessary, depending on the answer to the first qustion I asked.
How exactly is the "All Shipments" tab being updated with new data?
Is it a link? Some automated process? Or are people manually adding data to it?

If it being done manually, we can probably have it automatically copy over as they are entering the new data.
 
Upvote 0
OK, how many columns are being filled in per row?
Is there a certain order, so we could create some automated code that says once a certain column's entry is completed, we can check and copy it over to the "Shoe Show" sheet, if it meets our criteria?
 
Upvote 0
Up to column W, but once column E is filled out we can copy it over to "Show Show"
 
Upvote 0
OK, then go to your "ALL SHIPMENTS" sheet, right-click on the sheet name tab at the bottom of your sheet, select "View Code", and paste this code in that VB Editor window:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim nr As Long

'   Limit code to run only if update to column F
    If Target.Count > 1 Or Target.Column <> 6 Then Exit Sub
    
'   See if value just updated in column F contains "SHOE SHOW"
    If Target.Value Like "*SHOE SHOW*" Then
'       Find next available row on "Shoe Show" sheet
        nr = Sheets("Shoe Show").Cells(Rows.Count, "F").End(xlUp).Row + 1
'       Copy data
        Target.EntireRow.Copy Sheets("Shoe Show").Cells(nr, "A")
    End If

End Sub
Because you have placed this code in the appropriate sheet module, it will run automatically whenever "SHOE SHOW" is entered in column F.
 
Upvote 0
Wow! Thank you so much!
And if I want to run different macros based on different values in different columns, then I can just change anywhere where it says "Shoe Show" to the new value and anywhere where it says "F" to the new column and it will work?
 
Upvote 0

Forum statistics

Threads
1,215,165
Messages
6,123,390
Members
449,098
Latest member
ArturS75

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