+ Reply to Thread
Results 1 to 3 of 3

Application.Match returns Error 2042 whene text absolutely does exist?

Hybrid View

  1. #1
    Forum Contributor Rhudi's Avatar
    Join Date
    03-08-2013
    Location
    South Carolina, US
    MS-Off Ver
    Professional Plus 2016 aka Office 365
    Posts
    201

    Application.Match returns Error 2042 whene text absolutely does exist?

    I don't need to driven crazy, it's close enough to walk...

    I'm posting this for the next guy that might need it.

    I've been working for months on a very large macro/vba task to simplify router data research.

    x() is an array that is loaded from a text file, using:
    x = Split(CreateObject("Scripting.FileSystemObject").OpenTextFile(rName(rCount)).ReadAll, vbCrLf) ' x-Array will contain router dump

    I can expand that array in the debug window and find the text I'm trying to find. So, I know it's there.

    In part of my code, I have this line:
    z = Application.Match("router bgp ", x, 0)

    It returns Error 2042 and I figured it out.

    z = Application.Match("router bgp *", x, 0)

    Turns out "Application.Match" matches the entire line and is happy with wild cards.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Application.Match returns Error 2042 whene text absolutely does exist?

    Is this solved?

    If you solve a problem yourself before anyone else has responded, please take a moment to describe your solution, chances are some other member will benefit.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Contributor Rhudi's Avatar
    Join Date
    03-08-2013
    Location
    South Carolina, US
    MS-Off Ver
    Professional Plus 2016 aka Office 365
    Posts
    201

    Re: Application.Match returns Error 2042 whene text absolutely does exist?

    Yes, I solved this, by realising that "Application.Match" defaults to an exact match, and wildcards must be used if a partial match is ok.
    Also, a little care should be taken so if the match does fail, you don't get stuck with an error. I can't "Dim z As Integer", the code will die if I do get an error.

    In my example, I do this:
    z = Application.Match("router bgp *", x, 0)
    If IsError(z) Then
        msgbox "deal with text not in array"
    Else
        z = z - 1
        msgbox x(z)
    End If
    The only trouble I have now is dealing with duplicate data. I need an elegant way to do that, but will figure it out in a different thread.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Error 2042 with Application.Match
    By mgurren in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-08-2013, 02:15 AM
  2. [SOLVED] Error 2042
    By GreenTee in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-26-2013, 12:27 AM
  3. [SOLVED] Error 2042 with application.vlookup for date
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2013, 03:57 AM
  4. [SOLVED] Error 2042
    By magix in forum Excel General
    Replies: 3
    Last Post: 12-12-2005, 08:20 PM
  5. application.match Returns what
    By ben in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2005, 10:06 AM

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