+ Reply to Thread
Results 1 to 15 of 15

Object Required error on Application.Match function.

  1. #1
    Registered User
    Join Date
    04-05-2011
    Location
    Central New York State
    MS-Off Ver
    Excel 2007
    Posts
    13

    Object Required error on Application.Match function.

    The code below is throwing a Run-Time Error 424 - Object Required. The bolded line below is highlighted by the debugger. I've also checked the values while debugging; sdcon is the date that it should be (6/6/2011, based on the cell I've been starting with). I've also deliberately set the dates range as the exact cell it should be, which it shows up as when I check the value during debugging, but no matter what I've done to that formula, I cannot get past the Object Required error.

    And ideas, please? This is driving me insane because I'm so close to being done with this project...

    Thanks!


    Please Login or Register  to view this content.
    Last edited by ctckark1; 06-12-2011 at 10:59 AM.

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Object Required error on Application.Match function.

    Is the value of sdcon the same data type as the values in the "dates" range?
    Last edited by teylyn; 06-09-2011 at 08:14 PM.

  3. #3
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Object Required error on Application.Match function.

    txt_Start.Text is not declared in the sub. What does it refer to?

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Object Required error on Application.Match function.

    try changing sdcon and edcon to

    Please Login or Register  to view this content.
    The dates are stored as numbers, and the match with the formatted date does not work, whereas in my tests, the match with the number formatted as "general" does.

    cheers,

  5. #5
    Registered User
    Join Date
    04-05-2011
    Location
    Central New York State
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Object Required error on Application.Match function.

    My apologies I had been fighting with this about 4 hours straight with no headway yesterday, I neglected to explain anything...

    txt_Start & txt_End are text boxes on the form that calls this sub, user is requested to enter as dates (US format - m/d/yyyy). I can't require a specific format obviously... I would love to use a date picker but MS pulled that out of Excel 07.

    What this command is doing is taking a range of dates the user enters (txt_Start & txt_End), and an option they choose (Vacation, Leave of Absence, Schedule Change) for a given employee and adjusting their schedule between the days. All 365 days of the year are on row 2 (there's a few headings before that for name and id number, etc...) - Where I had the 'do work' comment is where the actual editing for each cell between dstart and dend is done. I haven't gotten that part tested because I can't get past the Match to find the column references for the start and end points...


    I did try changing the code as you mentioned, teylyn, and it continue to give me the same error.

    Dumb question, since I never had to use "set" when I program in true VB.net, what are the differences between using set and not using set? If I remove the "set" from the app.match lines I get Object variable or With block variable not set but if I add "set" to other spots, like the "Format$" lines I then get the Object Required errors at that point instead.

  6. #6
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Object Required error on Application.Match function.

    Hello,

    you need to use the "Set" keyword when you assign values to an object. For variables, you can just use the x = "something".

    I assume that the dates in the range you are using in the Match function are real dates. Excel stores dates as numbers. So, when you format the search value as text, there will be no match.

    Therefore, format the search value as a number before conducting the search.

    Using Format$ will normally force the result to be a string (because of the $). Try to use the Format function without the $ and make sure that the variables scdon and edcon are numbers, not text, before the Match is performed.

    In any case, the data type of sdcon and edcon need to be the same as the data type of the values in the "dates" range.

    It's really hard to troubleshoot this without seeing the Excel file, the User form and the underlying data.

  7. #7
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Object Required error on Application.Match function.

    Match returns a number, not an object, so remove the Set keywords from both that and the next line.
    Remember what the dormouse said
    Feed your head

  8. #8
    Registered User
    Join Date
    04-05-2011
    Location
    Central New York State
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Object Required error on Application.Match function.

    I did change the Format lines to use the Datevalue() function, this still shows the date without quotes when I hover over in debug mode, same as the format() function showed, whereas the original textbox values did show the quotes as strings.

    I still receive the object required error... Also, when I try to remove the "set" from the match lines I get the Object Variable error I mentioned above.

    I've attached a copy of the file, stripped to only three schedules, and with no identifiable data, just so you can see what is going on. This workbook is used as not only a master schedule for the employees, but also to keep "backup" (not the official) records of vacation usage, extended leave, and call-outs for employees. A lot of people edit this, and recently we've seen a rash of people editing things incorrectly (we used to just manually change the data) so we decided to try and make it more fool-resistant (not quite foolproof) that may include password-protecting sheets in the future when the scripting is complete and working right.

    Double-clicking on a cell in the main schedule area will show a window to select call-outs and vacation. Pressing the extra button on the bottom or double clicking a name will show the schedule adjustment window where extended vacations, leaves of absence (extended approved leave for medical reasons, etc) and the actual schedule can be adjusted for that person. It is on this schedule form that this issue is occurring, before it even begins to edit the data. It fails at trying to decide which cells need to be changed.


    I should warn you that while I have been programming VB.Net and VBA for a couple years now, I tend to work more in the immediate logical sense, as in I know what I want done and figure it out as I go, so the code tends to be very inconveniently laid out for anyone experienced enough to take a truly programmatical approach. I apologize and if you have any pointers on things here that could be consolodated or improved let me know.


    Again, THANK YOU for all your help, and when I get this straightened out, your reputations will not go unforgotten!
    Attached Files Attached Files

  9. #9
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Object Required error on Application.Match function.

    Try:
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    04-05-2011
    Location
    Central New York State
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Object Required error on Application.Match function.

    No dice - now I get a 1004 error: Application-defined or object-defined error. Debugging highlights the set cstart line you gave me. I did comment the old lines out.

  11. #11
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Object Required error on Application.Match function.

    Then I suspect the match is failing (I'm not at a pc to check just now).

    What do you get with:
    Please Login or Register  to view this content.
    Last edited by romperstomper; 06-10-2011 at 01:24 PM.

  12. #12
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Object Required error on Application.Match function.

    Please Login or Register  to view this content.
    Last edited by snb; 06-10-2011 at 03:12 PM.



  13. #13
    Registered User
    Join Date
    04-05-2011
    Location
    Central New York State
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Object Required error on Application.Match function.

    The msgbox gives me a type mismatch, regardless of whether I display only sdcon or dates.

    snb, both of those still result in object required errors if I leave set in, and the object variable error it I take set out.

    Is there some other way I should be trying to do this? Is match maybe not the best? (Now that you can see the file and what it is actually trying to act on?

  14. #14
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Object Required error on Application.Match function.

    - do not use set
    - make the correct reference to the sheet:
    - take care to enter a valid date, that also is part of row 2 in txt_End (e.g. cdate("06-09-2011") )


    Please Login or Register  to view this content.
    Last edited by snb; 06-11-2011 at 08:07 AM.

  15. #15
    Registered User
    Join Date
    04-05-2011
    Location
    Central New York State
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Object Required error on Application.Match function.

    snb, thanks! It finally worked! I knew Excel was super picky, but I assumed it would at least take the sheet index instead of the name... Obviously makes it a little tougher when we get to 2012, but maybe I'll have something else going by then, who knows.

    Thanks all! Reps added to all around!

+ 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