+ Reply to Thread
Results 1 to 14 of 14

Code states Match argument not optional

  1. #1
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Code states Match argument not optional

    Col H contains the range of possible "Grades". Col I contains the range of equivalent weighted "Scores"

    Col A contains Expected grades. Col B contains Actual grades (where known).

    Following Code should work as follows:

    If Col B does not match a "Grade" in Col H, then Col C is the "Index" of Col I that "Match" Col A against "Grade" in Col H
    Otherwise Col C is the Index/Match of the Grade in Col B

    But it throws a "Compile error" that "Match argument is not optional."

    Please Login or Register  to view this content.
    I know I could use the "formula" approach, but in this case I need a specific VBA solution.

    Any pointers, solutions or alternative welcome as ever.

    Ochimus
    Attached Files Attached Files
    Last edited by Ochimus; 05-05-2018 at 11:53 AM.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Code states Match argument not optional

    Unfortunately the link you posted doesn't work.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Code states Match argument not optional

    Sorry. Mumps?

    Don't understand the comment?

    If you refer to the file I attached, it opens perfectly from the link on both my desktop and a separate Laptop.

    Ochimus

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Code states Match argument not optional

    The first few times I tried the link, it wasn't working. I tried again and I was able to download your file. My apologies but I am a little confused by your explanation. Could you please explain using a few examples from your data in the file and stating what the result would be in column C for each example?

  5. #5
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Code states Match argument not optional

    Mumps,

    There are three examples in the file already, and the expected results are shown in COl E, headed "S/Be".

    In row 2, there is an "actual" grade (2) in Col B. So the Code needs to look in Col I for whatever matched "2" in Col H - the answer is 3, as shown in E2.
    In row 3, there is no "actual" grade in Col B, so the code needs to look at the value in Col A (2) and find the equivalent for that - the answer is 3, as shown in E3
    In row 3, there is an "actual" grade in Col B (D), so the code needs to look in COl I for that equivalent - the answer is 4, as shown in E4

    Hope that will hep find the flaw in the VBA code?

    Ochimus

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Code states Match argument not optional

    Try:
    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Code states Match argument not optional

    Mumps,

    Interesting approach, but sadly doesn't work if B2 has something "non-Grade".

    Example: Type "Z" in B2 and run the Macro.

    Because B2 is now not blank, your code will look only at the first instruction and seek the matching value in the "SCORE" range in Col I.

    As there is no match, C2 remains blank.

    That's why I wanted the "IF ERROR INDEX/MATCH" approach, That would trigger the "Error Message" in C2 if no match could be found, and the Code will move to the alternative sequence, and match whatever is in Col A.

    Ochimus

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Code states Match argument not optional

    Here you go.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  9. #9
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Code states Match argument not optional

    bakerman,

    Perfect!

    I'll mark this as solved, although I'm still unclear why my original ".match" generated the error whilst your structure doesn't?

    Ochimus

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Code states Match argument not optional

    You hadn't mentioned that column B could have something "non-Grade". If you are still interested, this should work.
    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Code states Match argument not optional


    Hi !

    In case of not matching can't work with WorksheetFunction. Never use it but just Application
    (example : Application.Match) and check result as error when can't match …
    Last edited by Marc L; 05-06-2018 at 08:47 AM.

  12. #12
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Code states Match argument not optional

    Marc,

    Thanks for the tip.

    Interesting it actually conflicts with MS's own Developer Network, which says to use "Worksheet Function" when writing Visual Basic for Excel, because a Function may have the same name as a Microsoft Excel Function, but work differently. (e.g. "Application.WorksheetFunction.Log" and "Log" will return different values!)

    Mumps,
    Point taken, and I should have considered that as a factor at the start, given the infinite capacity we have all experienced of End Users doing something completely "left field" and irrational. The results are actually downloaded from an online form, so I could always attempt to persuade the programmers to add DropLists that force the applicants to enter only valid values. (Good Luck with that!!).

    Ochimus

  13. #13
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Code states Match argument not optional

    No problem. I'm glad that it all worked out in the end.

  14. #14
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Code states Match argument not optional

    Quote Originally Posted by Ochimus View Post
    Interesting it actually conflicts with MS's own Developer Network, which says to use "Worksheet Function" when writing Visual Basic for Excel, because a Function may have the same name as a Microsoft Excel Function, but work differently. (e.g. "Application.WorksheetFunction.Log" and "Log" will return different values!)
    No conflict as you misread :

    instead of Application.WorksheetFunction.Log just use Application.Log for exactly same result !

+ 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. Sub argument is not optional
    By Atom in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-28-2017, 05:32 AM
  2. Argument not Optional
    By WesRuss in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-25-2016, 09:49 PM
  3. [SOLVED] Optional declared argument is not optional
    By tnuis in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-28-2015, 06:59 AM
  4. Argument not optional error is occurring in goal seek automated code.
    By bk1202 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-21-2013, 08:32 AM
  5. 'Argument not optional'
    By swoop99 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-15-2011, 03:27 PM
  6. msgbox: Argument not optional
    By tariq1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-24-2011, 06:15 AM
  7. Argument Not Optional
    By mccrimmon in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-14-2011, 12:59 PM

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