title: VBA Removing duplicates in an array
body: <p>I have a string that looks like "apples//apples//oranges//" I'm getting an error "subscript out of range" when I try to remove duplicates. </p>
  
  <p>I want my end result to look like "apples//oranges//"</p>
  
  <pre><code>Dim duplicateArray() As String
  Dim programsArray() As String
  
  duplicateArray() = Split(Sheets("Sheet1").Cells(1, 12).Value, "//")
  
  For j = 0 To UBound(duplicateArray)
      If UBound(Filter(programsArray, duplicateArray(j))) &gt; -1 Then
  
      Else
      programsArray(UBound(programsArray()) + 1) = duplicateArray(j)
  
      End If
  
  Next j
  
      programElement = Join(programsArray, " // ")
      Sheets("Sheet1").Cells(1, 3).Value = programElement
  </code></pre>