+ Reply to Thread
Results 1 to 8 of 8

Adding an Array as parameters of a function

  1. #1
    Registered User
    Join Date
    07-18-2017
    Location
    CAPE TOWN
    MS-Off Ver
    O365
    Posts
    9

    Adding an Array as parameters of a function

    I'm trying to add an array of values as parameters to my code for creating a chart but not sure how to do it.
    This is what my code looks like at the moment. I'm want to be able to add the x and y values as parameters as well. Any suggestions will be appreciated.
    Please Login or Register  to view this content.
    Thank you
    Louis
    Last edited by 6StringJazzer; 09-01-2017 at 08:53 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Adding an Array as parameters of a function

    It's unclear what you mean. You set ads (which is declared as Variant) to an array. Are you saying that you want to made ads a parameter to this function, instead of setting it inside the function? If so, simply add

    Please Login or Register  to view this content.
    as a parameter.

    x and y are strings. But if you are passing ads as a parameter, why would you need to pass x and y series? They are already in the array. That's one of the things that's confusing about your question.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Adding an Array as parameters of a function

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer

  4. #4
    Registered User
    Join Date
    07-18-2017
    Location
    CAPE TOWN
    MS-Off Ver
    O365
    Posts
    9

    Re: Adding an Array as parameters of a function

    Thank you for the feedback. What I'm trying to do is build re-usable code for creating charts.
    This is more of the code:

    Please Login or Register  to view this content.
    What I want to do is to be able to pass the series as parameters - the example above only have 2 series but it could be more. My current work have 7 different graphs, each using different series data.
    Regards
    Louis
    I hope it is more understandable.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Adding an Array as parameters of a function

    There is more than one way to do this, depending on how you are building the information to make the call to CreateChart.

    You asked about passing an array but you are passing discrete values: x values, series 1, series 2. You could just pass those three parameters. Will these charts have a number of series that vary arbitrarily? Or is it always the same number of series? If there is an arbitrary number of series, you can pass a parameter array (which is different than passing an array). That is, you can make a parameter array the last parameter, and pass as many series as you want.

    Also, you can pass strings that can be used to create the series, as you have done above, but that means you are hard-coding the series. Another option is to build the string from a range, which could be dynamic.

    So I kind of see what you are trying to do but I don't have the whole context. This is a software design problem and I would need to understand your whole problem to provide the right solution.

  6. #6
    Registered User
    Join Date
    07-18-2017
    Location
    CAPE TOWN
    MS-Off Ver
    O365
    Posts
    9

    Re: Adding an Array as parameters of a function

    Thank you for the response.

    I have to build a number of charts from various ranges (series) with different number of series. Currently I'm hard-coding the series in the Functions as :

    Please Login or Register  to view this content.
    or in a different Function :

    Please Login or Register  to view this content.
    The Functions are called by the following code:

    Please Login or Register  to view this content.
    What I would like to be able to do is to add the series as parameters to the Claims_charts() module.

    In the meantime I will investigate the parameter array option.

    I hope I explained it better.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Adding an Array as parameters of a function

    The simplest way is to build the array in ads as you have shown in your example, then make ads a parameter. You would modify the code above as follows (add red code, remove blue underlined code):

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-18-2017
    Location
    CAPE TOWN
    MS-Off Ver
    O365
    Posts
    9

    Re: Adding an Array as parameters of a function

    Thank you for the response, I will try it.

+ 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] adding a IF function to an array formula? is this possible?
    By cnak in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-17-2017, 09:42 AM
  2. [SOLVED] Array parameters in different file
    By Benoot in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 11-20-2013, 05:26 PM
  3. Array parameters?
    By Fat Al in forum Excel General
    Replies: 3
    Last Post: 02-08-2012, 03:01 AM
  4. adding another column to the search parameters
    By shy07014 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-18-2009, 02:16 AM
  5. adding another column to the search parameters...
    By shy07014 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-15-2009, 05:16 PM
  6. Passing Array's As Parameters
    By chuckury in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-26-2008, 10:08 AM
  7. [SOLVED] Array Parameters as Variants Only
    By TheVisionThing in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-25-2005, 06: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