+ Reply to Thread
Results 1 to 5 of 5

running a function with multiple variables left blank

  1. #1
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Question running a function with multiple variables left blank

    Trying to figure out how to run a function that takes 3 variables, but would like the last two variables to be optional, so that if they are not entered, the function assumes default values. Trying to use length of variable, but it's not working. In the end result, would like to be able to type in =test_function(=A1,,) and have it work the same is if I typed =test_function(=A1,200,63). Is there something else simple I can use to test if var2 and var3 have been entered?

    Please Login or Register  to view this content.
    Thanks
    You either quit or become really good at it. There are no other choices.

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: running a function with multiple variables left blank

    Change your first line to Function test_function(var1 As String, Optional var2 As Integer, Optional var3 As Integer)

  3. #3
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Re: running a function with multiple variables left blank

    Quote Originally Posted by JieJenn View Post
    Change your first line to Function test_function(var1 As String, Optional var2 As Integer, Optional var3 As Integer)
    Thanks! That works. Is there a simpler test I can do vs. Len(var2), like

    Please Login or Register  to view this content.
    Or similar syntax?

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: running a function with multiple variables left blank

    A "missing" number variable is considered with a value of 0. So as var2 and var3 are declared as integers, if they are omitted they are considered to be 0.

    Please Login or Register  to view this content.
    Which is fine, unless you also want to be able to pass 0 as a valid variable value... It may be better to declare those variables as variants, then you can check if they are numbers, and assign default values if not:

    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  5. #5
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Re: running a function with multiple variables left blank

    Got it! Thanks.

+ 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. Sigma Sum function with multiple variables
    By MVictorH in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-22-2015, 10:08 AM
  2. SEARCH function for multiple variables - VLOOKUP?
    By Texastom123 in forum Excel Formulas & Functions
    Replies: 46
    Last Post: 02-11-2014, 02:09 PM
  3. IF function with multiple variables
    By se7en in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 07-13-2013, 01:45 PM
  4. [SOLVED] Sum Function based on multiple variables
    By Mr. H2 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 02-27-2013, 02:42 PM
  5. [SOLVED] If And Or Left function in multiple cells
    By sans in forum Excel General
    Replies: 13
    Last Post: 04-24-2012, 04:30 AM
  6. Function for Multiple Variables
    By leynadsvision in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-18-2008, 11:54 AM
  7. if function multiple variables
    By cin in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-08-2005, 05:05 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