title: checking if value present in array
body: <p>I'm using a function from <a href="https://stackoverflow.com/questions/10951687/how-to-search-for-string-in-ms-access-vba-array">this</a> question, however, it doesn't seem to work in my case.</p>
  
  <p>Basically, this script is going through a column selecting distinct values and populating array <code>arr</code> with them. First <code>If</code> is checking if the column has ended, then to avoid calling empty array I have the first <code>IfElse</code>, and finally I want to check a non-empty array for <code>cell</code> string. If it is not present, I want to add it.</p>
  
  <pre><code>Public Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean
    IsInArray = (UBound(Filter(arr, stringToBeFound)) &gt; -1)
  End Function
  
  Sub SelectDistinct()
  
      Dim arr() As String
      Dim i As Integer
      Dim cells As Range
  
      Set cells = Worksheets("types").Columns("A").Cells
  
      i = 0
      For Each cell In cells
          If IsEmpty(cell) Then
              Exit For
          ElseIf i = 0 Then
              ReDim Preserve arr(i)
              arr(UBound(arr)) = cell
              i = i + 1
          ElseIf IsInArray(cell.Value, arr) = False Then
              ReDim Preserve arr(i)
              arr(UBound(arr)) = cell
              i = i + 1
          End If
      Next cell
  End Sub
  </code></pre>
  
  <p>For some reason, it throws "Subscript out of range" error on the call of <code>IsInArray</code> function. Can someone let me know where I went wrong?</p>