+ Reply to Thread
Results 1 to 5 of 5

Mismatch occurance in Array

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Mismatch occurance in Array

    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

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Mismatch occurance in Array

    Hello dbd1974,

    The code you posted doesn't appear to be complete. Is the RegExp object declared as Public in a Module? Where is the pattern string declared?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Mismatch occurance in Array

    You can only Redim Preserve an array, which FolderList isn't when that statement is executed. Either remove Preserve, or declare as FolderList().
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Mismatch occurance in Array

    Hi Leith and Shg,

    I'm glad to have you both reply.

    Leith,

    To be honest, I 'm not sure how it was declared.
    I tried attaching a chopped down version of my WB with the code for you to take
    a look at it. However, the forum's uploader seems to be having issue. I hope
    you don't mind, but I sent the WB to your g-mail.

    To start or run,click on button "Go To Entry Form"
    Next, click inside the IMP box on the form to start the code.

    I apologize for it being so messy. There's a lot of lines I've commented out.

    Thanks,

    BDB

  5. #5
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Mismatch occurance in Array

    Here's my wb with issues.

    Open . goto entry form.
    Click in IMP box.
    I would like for it to list all unique values in col F for the value given in Stock# box.

    Thanks,

    BDB

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1