+ Reply to Thread
Results 1 to 3 of 3

Setting variable equal to match result- error 2042

  1. #1
    Registered User
    Join Date
    05-28-2019
    Location
    Indianapolis
    MS-Off Ver
    Excel 2016
    Posts
    12

    Setting variable equal to match result- error 2042

    Hello everyone,
    I am trying to write a macro that will first find what row number of a worksheet contains the column headers of some data, then searches that row for specific column names. In the long run, I plan to do it by using some kind of loop that will, using MATCH, search column A for every possible column header until it finds one.

    For now, I am just trying to use the MATCH function to search for one particular column header. I have a variable set equal to the MATCH function. My problem is that I keep getting error 2042 as the value of the variable, even though the header I am searching for is in column A of the worksheet I'm searching. I'm hoping that I'm just making some stupid syntax error, and that one of you might be able to see what it is.

    Here is just the relevant line:
    Please Login or Register  to view this content.

    Thanks in advance!


    Here's my entire module, in case anyone actually wants to see it:
    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,002

    Re: Setting variable equal to match result- error 2042

    Is the value you are looking for definitely in cell A10 of the worksheet wbCW.Sheets(1) refers to?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    05-28-2019
    Location
    Indianapolis
    MS-Off Ver
    Excel 2016
    Posts
    12

    Re: Setting variable equal to match result- error 2042

    Norie: Apparently that was my issue, I feel like such an idiot. I had an extra space in the spreadsheet that wasn't in the code! Sometimes I just need to step away from the computer and come back later.

+ 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