+ 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,643

    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)

Similar Threads

  1. Modify DateTime for Application.Match - error 2042
    By domgilberto in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-21-2016, 09:02 AM
  2. [SOLVED] Error 2042 for application.match
    By a.hudrea in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2016, 03:41 AM
  3. setting variable equal to a value in a cell
    By ualdriver in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 02-25-2015, 06:01 AM
  4. Error 2042 on Application.Match formula
    By krazyhype19 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-05-2015, 03:25 AM
  5. [SOLVED] Error 2042 using Application.Match to add item and update combobox list
    By newbi004 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2013, 07:55 AM
  6. [SOLVED] Application.Match returns Error 2042 whene text absolutely does exist?
    By Rhudi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2013, 04:21 PM
  7. Error 2042 with Application.Match
    By mgurren in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-08-2013, 02:15 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