Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 1st, 2012  |  syntax: None  |  size: 1.20 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. find unique dates in excel vba array
  2. _Here is my dataset:_  
  3. 12/07/2010     3.5
  4.  
  5. 12/07/2010     2.1
  6.  
  7. 12/07/2010     2.2
  8.  
  9. 12/08/2010     5.2
  10.  
  11. 12/08/2010     3.2
  12.  
  13. 12/09/2010     4.7
  14.        
  15. 12/07/2010
  16.  
  17. 12/08/2010
  18.  
  19. 12/09/2010
  20.        
  21. Sub Uniques()
  22.     Dim oColl As New Collection
  23.  
  24.     Dim vArr As Variant
  25.     Dim vItem As Variant
  26.     Dim j As Long
  27.     vArr = Range("A1:B6")
  28.     On Error Resume Next
  29.     For j = LBound(vArr) To UBound(vArr)
  30.         oColl.Add vArr(j, 1), CStr(vArr(j, 1))
  31.     Next j
  32.     On Error GoTo 0
  33.  
  34.     For Each vItem In oColl
  35.         Debug.Print vItem
  36.     Next vItem
  37. End Sub
  38.        
  39. Sub test()
  40.  
  41.     Dim vItem As Variant
  42.     Dim vArray(5) As Variant
  43.  
  44.     vArray(0) = CDate("12/07/2010")
  45.     vArray(1) = CDate("12/07/2010")
  46.     vArray(2) = CDate("12/07/2010")
  47.     vArray(3) = CDate("12/08/2010")
  48.     vArray(4) = CDate("12/08/2010")
  49.     vArray(5) = CDate("12/09/2010")
  50.  
  51.     Dim colDates As Collection
  52.  
  53.     Set colDates = New Collection
  54.  
  55.     On Error Resume Next
  56.  
  57.     For Each vItem In vArray
  58.         colDates.Add vItem, CStr(vItem)
  59.     Next vItem
  60.  
  61. End Sub
  62.        
  63. arTargetArray as Array
  64.  
  65. For each Item in your_array
  66.   value = Filter(arTargetArray, Item)
  67.   if value null
  68.     add item to  arTargetArray.
  69.   end if
  70. next each