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

  • Home
  • SEARCH
  • 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 8137141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:00:01+00:00 2026-06-06T11:00:01+00:00

I am working with an array of 2D arrays in Excel VBA. I have

  • 0

I am working with an array of 2D arrays in Excel VBA. I have a function…

Public Function constructStack(vbr() As Variant, hr As Integer) As stack

Where stack is a class I made. I have another function, in which I am calling constructStack from. here is the call:

Set stacks(i) = stack(i).constructStack(vbr(i), i)

vbr happens to be an array of 2D arrays. Seeing as vbr(i) would refer to a single 2D array of type variant, I’m confused why I’m getting the “Type mismatch: array or user-defined type expected,” compile error.

It’s almost as if the compiler doesn’t realize that vbr() will be filled with 24 2D arrays, which is why it’s giving me the compile error. Here is how I Dim vbr:

Dim vbr(1 To 24) As Variant

After declaring vbr, I eventually run this for loop which assigns each element of vbr a 2D array…

vb = GetVBRSorted
For j = 1 To 24
    For i = 2 To 2000
        If (vb(i, 1)(j) <> "") Then
          lastFilleds(j) = i
        End If
    Next
Next
For j = 1 To 24
    ReDim vbrTemp(1 To lastFilleds(j) - 1, 1 To 5)
    For i = 2 To lastFilleds(j)
        For k = 1 To 5
            vbrTemp(i - 1, k) = vb(i, k)(j)
        Next
    Next
    vbr(j) = vbrTemp
Next

GetVBRSorted returns the exact same type as vbr – an array of 2D arrays. If anyone has any input on this issue, it would be much appreciated.

  • 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-06-06T11:00:03+00:00Added an answer on June 6, 2026 at 11:00 am

    Because each individual vbr(i) is a Variant, this is what you must declare as your parameter type. There is no magical compile-time sniffing to realise the Variant contains an array.

    Use

    Public Function constructStack(vbr As Variant, hr As Integer) As stack 
    

    Also see How can I use an optional array argument in a VBA procedure?.

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

Sidebar

Related Questions

I'm working with a dynamic array in Excel VBA. The number of columns (m)
I’m working on a multi dimensions array but i have a problem Imagine I
My problem: I have an JSON Array containing arrays, which i render into the
I'm working entirely in VBA for Excel. My solution must be entirely programmatic, and
I'm working on a parser for use at work. Basically I have an excel
Possible Duplicate: Java Generics: Array containing generics I have a Java class which contains
So Im working on a Excel xml parsing class, and Im trying to search
I have a nested array of arrays, and I want to shuffle the inner
I'm having a hard time working with arrays. Coming from AS2/AS3 and garbage collection
I'm trying to sort any array with array_multisort() and everything is working great. However,

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.