+ Reply to Thread
Results 1 to 4 of 4

Type mismatch in arguments when I try to call a function

  1. #1
    Registered User
    Join Date
    12-27-2018
    Location
    Bogota, Colombia
    MS-Off Ver
    Excel 2013, 2016
    Posts
    25

    Type mismatch in arguments when I try to call a function

    Hi all. I wrote a function that I believe will be able to put out a value from a fairly complex table based on the values of three of its columns. This is said function

    Please Login or Register  to view this content.
    Now I think the function is likely to work, but since I'm standing on the shoulders of giants here, I'm working with a lot of stuff I've never used before, so to test it out I wrote the very simple call sub below:

    Please Login or Register  to view this content.
    The error I'm getting right of the bat is "Type mismatch" and the argument where the range goes is highlighted. I'd love it if someone could fix the problem, but more importantly, is this the correct way to call said function? I'm having a hard time figuring out based on the resources I've looked up.

    I've attached a sample workbook if it helps.
    Attached Files Attached Files
    Last edited by FZappa; 06-19-2019 at 04:30 PM.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Type mismatch in arguments when I try to call a function

    Few issues here.

    1. You should either use Err# instead of xlErrNA. Or define constant value for xlErrNA at start.
    xlErrNA = 2042

    2. The function should not be defined as returning Long. As you want to return error value (from use of xlErrNA)
    Use As Variant.

    3. Altrura should also be variant.

    4. "A6:L34" is string, you need to qualify it with sheet and range object.
    I.E. Sheet1.Range("A6:L34")

    5. Col is declared as Integer. So don't use double quote. When a number is nested in double quote, it's implicitly treated as string.

    Also, you were missing "." at end of Fecha value.

    So, something like below would work.
    Please Login or Register  to view this content.
    FYI - You really wouldn't need UDF for this. INDEX/IF() Array function, or INDEX/Aggregate combo should be able to handle it.
    Last edited by CK76; 06-19-2019 at 04:24 PM. Reason: Added FYI
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    12-27-2018
    Location
    Bogota, Colombia
    MS-Off Ver
    Excel 2013, 2016
    Posts
    25

    Re: Type mismatch in arguments when I try to call a function

    Oh man, thanks so much for that. I knew I had to be making some basic errors like that, I'm still finding the basic logic of excel a bit overwhelming. It works now!

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Type mismatch in arguments when I try to call a function

    You are welcome and thanks for the rep

+ 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. [SOLVED] Function 'as long' gives type mismatch
    By truk2 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-17-2019, 10:34 PM
  2. Type mismatch on call to QueryTables.Add
    By mogilshik in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-11-2018, 03:19 PM
  3. [SOLVED] Type mismatch when using Match function
    By Unome in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-21-2017, 06:23 PM
  4. [SOLVED] Type mismatch using worksheet object arguments in procedure
    By perducci in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-21-2012, 01:35 PM
  5. Match Function Type Mismatch
    By officialhopsof in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 06-14-2011, 02:58 AM
  6. Type Mismatch - Match function
    By T De Villiers in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-31-2006, 10:48 AM
  7. Type mismatch in look up function
    By bisjom in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-09-2006, 01:16 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