Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. Function ListCount(list As String, delimiter As String) As Long
  2. Dim arr As Variant
  3. arr = Split(list, delimiter)
  4. ListCount = UBound(arr) - LBound(arr) + 1
  5. End Function
  6.  
  7. Function RemoveDuplicates(list As String, delimiter As String) As String
  8. Dim arrSplit As Variant, i As Long, tmpDict As New Dictionary, tmpOutput As String
  9. arrSplit = Split(list, delimiter)
  10. For i = LBound(arrSplit) To UBound(arrSplit)
  11. If Not tmpDict.Exists(arrSplit(i)) Then
  12. tmpDict.Add arrSplit(i), arrSplit(i)
  13. tmpOutput = tmpOutput & arrSplit(i) & delimiter
  14. End If
  15. Next i
  16. If tmpOutput <> "" Then tmpOutput = Left(tmpOutput, Len(tmpOutput) - Len(delimiter))
  17. RemoveDuplicates = tmpOutput
  18. 'housekeeping
  19. Set tmpDict = New Dictionary
  20. End Function
  21.  
  22. Function UNIQUECOUNTIF(ByRef SR As Range, _
  23. ByRef RR As Range, _
  24. Optional ByVal Crit As Variant, _
  25. Optional NCOUNT As Boolean = False, _
  26. Optional POSTCODE As Boolean = False) As Long
  27. Dim K1, K2, i As Long, c As Long, x, n As Long
  28. K1 = SR: K2 = RR
  29. With CreateObject("scripting.dictionary")
  30. For i = 1 To UBound(K1, 1)
  31. If Not IsMissing(Crit) Then
  32. If LCase$(K1(i, 1)) = LCase$(Crit) Then
  33. If POSTCODE Then
  34. x = Split(Replace(LCase$(K2(i, 1)), ",", " "), " ")
  35. Else
  36. x = Split(LCase$(K2(i, 1)), ",")
  37. End If
  38. For c = 0 To UBound(x)
  39. If POSTCODE Then
  40. If IsNumeric(x(c)) Then
  41. If Not .exists(x(c)) Then
  42. .Add x(c), 1
  43. ElseIf NCOUNT Then
  44. .Item(x(c)) = .Item(x(c)) + 1
  45. End If
  46. End If
  47. Else
  48. If Not .exists(x(c)) Then
  49. .Add x(c), 1
  50. ElseIf NCOUNT Then
  51. .Item(x(c)) = .Item(x(c)) + 1
  52. End If
  53. End If
  54. Next
  55. End If
  56. Else
  57. If POSTCODE Then
  58. x = Split(Replace(LCase$(K2(i, 1)), ",", " "), " ")
  59. Else
  60. x = Split(LCase$(K2(i, 1)), ",")
  61. End If
  62. For c = 0 To UBound(x)
  63. If POSTCODE Then
  64. If IsNumeric(x(c)) Then
  65. If Not .exists(x(c)) Then
  66. .Add x(c), 1
  67. ElseIf NCOUNT Then
  68. .Item(x(c)) = .Item(x(c)) + 1
  69. End If
  70. End If
  71. Else
  72. If Not .exists(x(c)) Then
  73. .Add x(c), 1
  74. ElseIf NCOUNT Then
  75. .Item(x(c)) = .Item(x(c)) + 1
  76. End If
  77. End If
  78. Next
  79. End If
  80. Next
  81. If .Count > 0 Then UNIQUECOUNTIF = Application.Sum(.items)
  82. End With
  83. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement