PDA

View Full Version : Remove duplicated values from 1d string array vba



elyfrank
10-15-2017, 12:54 PM
Hi there,
I am trying to find a way to remove duplicated values in an array. This is the code I have so far which populates the array with no problem. I am new to arrays BTW.
I have tried to use Collections but I keep getting a type mismatch error.
Thanks a lot.

Dim Filename As String
Dim Filenames(0 To 100) As String
Dim i, x As Integer
Dim Path As String

For i = 2 To 10
If Cells(i, 2).Interior.ColorIndex = 43 Then
Filename = Path + Sheet1.Cells(i, 1)
x = x + 1
Filenames(x) = Filename
End If
Next i

mikerickson
10-15-2017, 04:00 PM
Try

If Cells(i, 2).Interior.ColorIndex = 43 Then
Filename = Path + Sheet1.Cells(i, 1)
If IsError(Application.Match(FileName, FileNames, 0) Then
x = x + 1
Filenames(x) = Filename
End If
End If