remove uniques between sheets

emukiss10

Board Regular
Joined
Nov 17, 2017
Messages
201
Hello,

- Sheets(1) column F from F2 to FXXX has some numbers
- Sheets(2) column E from E2 to EXXX has some numbers

I need to remove all rows in Sheets(2) based on those numbers (E) that are not present in Sheets(1) (F)

Please Help with VBA

Best Regards
W.
 
Untested, but try this
Code:
Sub RemoveOddsies()

   Dim Cl As Range
   Dim Rng As Range
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Sheets(1).Range("F2", Sheet(1).Range("F" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then .Add Cl.Value, Nothing
      Next Cl
      For Each Cl In Sheets(2).Range("E2", Sheets(2).Range("E" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then
            If Rng Is Nothing Then
               Set Rng = Cl
            Else
               Set Rng = Union(Rng, Cl)
            End If
         End If
      Next Cl
   End With
   If Not Rng Is Nothing Then Rng.EntireRow.Delete
      
End Sub
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Glad we help & thanks for the feedback
 
Upvote 0
Try the following macro (you can change the worksheet names in the macro):

Code:
Sub emukiss10()
' hiker95, 12/22/2017, ME1036307
Dim w1 As Worksheet, w2 As Worksheet
Dim r As Long, lr As Long, f As Range
Set w1 = Sheets("Sheets(1)")   '<-- you can change the sheet name here
Set w2 = Sheets("Sheets(2)")   '<-- you can change the sheet name here
With w2
  lr = .Columns(5).Find("*", searchdirection:=xlPrevious).Row
  For r = lr To 2 Step -1
    Set f = w1.Columns(6).Find(.Cells(r, 5).Value, LookAt:=xlWhole)
    If Not f Is Nothing Then
      .Rows(r).Delete
    End If
  Next r
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,201
Members
453,022
Latest member
RobertV1609

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