Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 994615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:36:09+00:00 2026-05-16T06:36:09+00:00

How do I pass multidimensional arrays or nested arrays into an Excel UDF which

  • 0

How do I pass multidimensional arrays or nested arrays into an Excel UDF which allow me to reference other ranges?

I have a UDF defined as “ARY” which does what Array() does in VBA but in a worksheet function.

This allows me to have a worksheet formula like

=TEST1(ARY(ARY(“A”, “B”), “C”))
or
=TEST1(ARY(ARY(A1, B1), C1)

However, I get Error 2015 when executing TEST1 as a worksheet function. If I execute TEST1 from VBA, it works fine and returns “A”.

Public Function TEST1(Params As Variant) As Variant
    TEST1 = Params(0)(0)
End Function

'Returns 1D ARRAY
Public Function ARY(ParamArray Params() As Variant)
    ReDim result(0 To UBound(Params)) As Variant
    Dim nextIndex As Integer
    Dim p As Variant

    nextIndex = 0

    For Each p In Params
        result(nextIndex) = p
        nextIndex = nextIndex + 1
    Next

    ARY = result
End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:36:10+00:00Added an answer on May 16, 2026 at 6:36 am

    In general, you can’t do this. VBA is fine with nested arrays as values, but Excel just isn’t. This makes sense, because Excel ultimately has to treat any values it gets from your UDFs as things that can go into the worksheet grid.

    It would be nice if intermediate results didn’t have to obey this restriction. In your example above, you’re not trying to put a jagged array into any cells; you just want to create it and pass it to ‘TEST1’. Unfortunately, Excel just doesn’t work that way. It evaluates each expression in a formula to a legal Excel value, and #VALUE! is the catch-all for “not a legal value”. (There are other limitations to returned arrays besides jaggedness. For example, arrays over a certain size also result in a #VALUE! error.)

    Note that nested arrays that are all the same length can be passed back from UDFs:

    Public Function thisKindOfNestingWorks()
        thisKindOfNestingWorks = Array(Array(1, 2), Array(3, 4))
    End Function
    

    This can be useful when you’re building up some list-of-lists that you actually want coerced to a 2-D array.

    So, calling your ARY function above like this should work just fine:

    =ARY(ARY(A1, B1), ARY(C1, D1))
    

    However, your TEST1 function would fail, since calling

    =TEST1(ARY(ARY(A1, B1), ARY(C1, D1)))
    

    would result in a 2-D array being passed to TEST1, not a 1-D array of 1-D arrays.

    You might also find this question and my answer to it to be helpful:

    Return a User Defined Data Type in an Excel Cell

    MUCH LATER EDIT:

    Incidentally, your ‘ARY’ function could be a lot shorter. This has nothing to do with your original question, but it’s worth mentioning:

    Public Function arr(ParamArray args())
         arr = args
    End Function
    

    There is an example of using it in this answer:

    Excel Select Case?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 499k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think I have an answer for you. Without seeing… May 16, 2026 at 12:31 pm
  • Editorial Team
    Editorial Team added an answer I'd create a named_scope (I think it's just scope in… May 16, 2026 at 12:31 pm
  • Editorial Team
    Editorial Team added an answer You can either use the DirectoryIterator: $dir = new DirectoryIterator('path/to/images');… May 16, 2026 at 12:31 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm writing a simple test program to pass multidimensional arrays. I've been struggling to
This question builds off of a previously asked question: Pass by reference multidimensional array
In C can I pass a multidimensional array to a function as a single
I'm storing an infinitely nested directory structure in mysql by assigning a parent_album_id to
I have a class to parse a matrix that keeps the result in an
I read the example on Passing multi-dimensional arrays in C on this site. It
I have an object with a Property of type byte[ , ,*] now i'd
How can I pass multiple arguments to a newly created process in C#? Also
How to pass a php json encoded variable to a jquery function using codeigniter?
I know how to pass one argument to a menu callback $items['someaddress/%'] = array(

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.