Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. Private Sub CommandButton1_Click()
  2.  
  3. Dim MasterList As New Dictionary
  4. Dim iListCount As Integer
  5. Dim x As Variant
  6. Dim iCtr As Integer
  7. Dim v As Variant
  8. Dim counter As Integer, i As Integer
  9. counter = 0
  10.  
  11. With Sheets("Sheet2")
  12. .Range("M:M").ClearContents
  13. .Range("S:S").ClearContents
  14.  
  15. Sheets("Sheet1").Range("C:C").Copy
  16. Sheets("Sheet2").Range("M1").Select
  17. ActiveSheet.Paste
  18.  
  19.  
  20. Sheets("Sheet1").Range("X:X").Copy
  21. Sheets("Sheet2").Range("S1").Select
  22. ActiveSheet.Paste
  23.  
  24. Application.ScreenUpdating = False
  25. Application.Calculation = xlCalculationManual
  26.  
  27. ' Get count of records in master list
  28. iListCount = .Cells(Rows.Count, "A").End(xlUp).Row
  29. 'Load Dictionary:
  30. For iCtr = 1 To iListCount
  31. v = .Cells(iCtr, "A").Value
  32. If Not MasterList.Exists(v) Then MasterList.Add v, ""
  33. Next iCtr
  34.  
  35. 'Get count of records in list to be deleted
  36. iListCount = .Cells(Rows.Count, "M").End(xlUp).Row
  37.  
  38. ' Loop through the "delete" list.
  39. For iCtr = iListCount To 1 Step -1
  40. If MasterList.Exists(.Cells(iCtr, "M").Value) Then
  41. .Cells(iCtr, "M").Delete shift:=xlUp
  42. .Cells(iCtr, "S").Delete shift:=xlUp
  43. End If
  44. Next iCtr
  45. End With
  46.  
  47. Application.ScreenUpdating = True
  48. Application.Calculation = xlCalculationAutomatic
  49.  
  50. MsgBox "Done!"
  51. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement