+ Reply to Thread
Results 1 to 6 of 6

Excel VBA Function with optional argument

  1. #1
    Registered User
    Join Date
    02-06-2016
    Location
    Switzerland
    MS-Off Ver
    2013
    Posts
    6

    Excel VBA Function with optional argument

    Dear Reader

    (i am using Excel 2013)

    i am trying to use a main function with 1 optional argument and i would like to give this optional argument to a second function (see below).
    the error message i am receiving is the following:
    "compile error:
    byref argument type mismatch"
    and "BoltType" is marked

    e.g.
    Please Login or Register  to view this content.
    i would be very happy when someone could help me out
    Last edited by blackgericom; 02-06-2016 at 01:01 PM.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,803

    Re: Excel VBA Function with optional argument

    I don't get any error involving the BoltType argument. The error it gives me is for the Type argument. I think this is because Type is a VBA keyword (maybe a reserved keyword that cannot be used as a variable/argument name). The procedures run without error if I change Type to sType or something like that.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel VBA Function with optional argument

    Hi blackgericom,

    "Type" is a reserved word - change it to "Tipe" or something else.

    And - Welcome to the Forum!
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Registered User
    Join Date
    02-06-2016
    Location
    Switzerland
    MS-Off Ver
    2013
    Posts
    6

    Re: Excel VBA Function with optional argument

    Sorry, the version above was a short example.

    here is the full version
    the whole line is marked yellow: Function MS_StdMatTemperatureFktBolt(Standard As String, Materialname As String, Temperature As Double, FunctionType As String, Optional BoltType As String) As Variant
    and the underlined "bolttype" is marked blue.

    Please Login or Register  to view this content.
    Last edited by blackgericom; 02-06-2016 at 12:50 PM.

  5. #5
    Registered User
    Join Date
    02-06-2016
    Location
    Switzerland
    MS-Off Ver
    2013
    Posts
    6

    Re: Excel VBA Function with optional argument

    ohh i see i forgot to give him the temperature...
    it works now, sorry and thanks for your fast answers :-)

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel VBA Function with optional argument

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here


    *You did this on your first post - please do it here.

    BTW - What is your question?

+ 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] Optional declared argument is not optional
    By tnuis in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-28-2015, 06:59 AM
  2. Using a Boolean function within an If statement: Argument not optional error message
    By elfsprin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-16-2011, 04:12 PM
  3. 'Argument not optional'
    By swoop99 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-15-2011, 03:27 PM
  4. Argument Not Optional
    By mccrimmon in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-14-2011, 12:59 PM
  5. Argument Not Optional error on click of Ctrl+V in Excel 2007
    By pgharat in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-11-2008, 05:03 AM
  6. 2nd. argument (Optional ) in COUNTA() function
    By Rabi in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-13-2007, 08:30 AM
  7. [SOLVED] optional argument in a function
    By visitor in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-13-2005, 03:06 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