I am using the function from this question, however it does not seem to work in my case.
Basically, this script goes through a column that selects different values for it and populates the arr array. If first checks to see if the column has ended to avoid calling an empty array. I have the first IfElse , and finally I want to check a non-empty array for the cell string. If it is not there, I want to add it.
Public Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean IsInArray = (UBound(Filter(arr, stringToBeFound)) > -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
For some reason, it throws a "Subtit out of range" error when calling the IsInArray function. Can someone tell me where I was wrong?
source share