Hi all,

I'm struggling on figuring out why and how to correct an mismatch error in part of my
code. The code works just fine in my test WB but placing the script into my main
WB , the script errors.

This is a Funtion Code. I've even tried changin Cnt as Integer to as Long but still errors.


Function MapFolders(DirPath As String, Optional Filter As Variant, Optional Cnt As Integer) As Long
  Dim WS2 As Worksheet
 'This uses an Array to import the filters and RegExp to do multiple matches
  Dim Folder As Object
  Dim Cell As Object
  Dim FindIt As Object
  Dim Item As Variant
  Dim FSO As Object
  Dim RegExp As Object
  Dim LastRow As Integer
  Dim FilterList As String
  Dim FolderList As Variant


  If RegExp.Test(Cell.Value) = True Then
           On Error Resume Next
           ReDim Preserve FolderList(Cnt) ' mismatch happens here
           'FolderList(Cnt) = Folder.Path
           FolderList(Cnt) = Cell.Offset(0, 4).Value
           Cnt = UBound(FolderList) + 1
        End If
        On Error Resume Next
          If Folder.SubFolders.Count > 0 Then
            MapFolders Folder.Path, Filter, Cnt
          End If
          If Err.Number = 70 Then Err.Clear   'Permission denied
        On Error GoTo 0
     'Next Folder
    ' End If
      Next Cell
To give an idea of what's happening, I have a userform textbox value for which I search for matches on a worksheet, if this match is found, then then the matching cell's offset (0,4).value is placed into an Array. Once the Array is built, then I check it for unique
values. The unique values then get placed into a listbox.

Anyhelp resolving this is appreciated.

Thanks,

BDB