Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. Private Sub Remove_Dubs_IndBB()
  2.  
  3. Dim i As Long
  4. Dim data As Integer
  5.  
  6. Application.ScreenUpdating = False
  7. Application.Calculation = xlCalculationManual
  8.  
  9. data = Range("A2", Range("A" & Rows.Count).End(xlUp)).Count
  10.  
  11. Call Sum_IF
  12. SendKeys ("{ESC}")
  13.  
  14. With Range("A2", Range("F" & Rows.Count).End(xlUp))
  15.  
  16. .Sort Key1:=Cells(1, 6), Order1:=xlDescending, _
  17. Header:=xlNo
  18.  
  19. For i = 1 To data
  20. If (VBA.Date - Cells(i, 4)) / 365 > 5 Then
  21. Range(Cells(i, 1), Cells(i, 6)).ClearContents
  22. End If
  23. If (Cells(i, 5) - VBA.Date) / 365 < 1.25 Then
  24. Range(Cells(i, 1), Cells(i, 6)).ClearContents
  25. End If
  26. Next i
  27.  
  28. Range("A2", Range("F" & Rows.Count).End(xlUp).Address).Select
  29. Selection.Sort Key1:=Columns(6), Order1:=xlDescending, _
  30. Header:=xlNo
  31.  
  32. Selection.Sort Key1:=Columns(2), Order1:=xlDescending _
  33. , Key2:=Columns(4), Order2:=xlDescending _
  34. , Key3:=Columns(5), Order3:=xlDescending _
  35. , Header:=xlNo
  36.  
  37.  
  38. Range("A2", Range("F" & Rows.Count).End(xlUp)).RemoveDuplicates (3), Header:=xlNo
  39.  
  40. End With
  41.  
  42. Application.ScreenUpdating = True
  43. Application.Calculation = xlCalculationAutomatic
  44.  
  45. End Sub
  46.  
  47. Sub Sum_IF()
  48.  
  49. Dim i As Long
  50. Dim data As Integer
  51.  
  52. data = Range("A2", Range("A" & Rows.Count).End(xlUp)).Count
  53.  
  54. With Range("A2", Range("F" & data))
  55. For i = 1 To data
  56. .Cells(i, 6).FormulaR1C1 = "=SUMIF(R2C3:R[" & data & "]C3, RC[-3], R2C2:R[" & data & "]C2)"
  57. .Cells(i, 6).Copy
  58. .Cells(i, 6).PasteSpecial xlPasteValues
  59. Next i
  60. End With
  61.  
  62. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement