+ Reply to Thread
Results 1 to 3 of 3

Type Mismatch when passing multi-dimensional array

  1. #1
    Registered User
    Join Date
    09-26-2018
    Location
    London
    MS-Off Ver
    O365 Plus
    Posts
    2

    Type Mismatch when passing multi-dimensional array

    Hi all,

    I've searched; and although I have found numerous threads about passing arrays - they don't seem to describe or solve the problem I'm having. I apologise if this has been answered and my search skills are as bad as my VBA. I decided not to stumble in the dark and registered so I could glean some information from you all.

    So I'm working with multiple workbooks. In the control book; I loop through a series of workbooks - open each one and loop within that book to extract some data which I then consolidate back in the control workbook.

    I have two sub-routines which do some work. The first creates 2 arrays; one 2 dimensional; and one single dimensional. To do this I defined the arrays upfront in my main sub-routine as follows:

    Please Login or Register  to view this content.
    The two sub-routines are declared with the variables passed as "byref". The only difference being that in the first sub-routine, I "ReDim" the arrays, using the keyword preserve to resize as needed; but in the second, I have no need to ReDim the arrays - just to use them.

    Please Login or Register  to view this content.
    The first call works like a charm and returns the filled arrays. The second hits an error, stating a type mismatch in the ByRef variable. Do you perhaps know why?

  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: Type Mismatch when passing multi-dimensional array

    Welcome to the Forum alxhix !

    You left out huge amounts of your code so I cannot reproduce your problem. When I reconstruct your code and run it, it runs fine. To reproduce your error we will need your entire file.

    However, you do have one bug, see red note. You need to refer to the second dimension of aCostingData for this loop, not the first dimension (which is 0 To 1). This bug will give you wrong results but does not cause the error you describe.
    Please Login or Register  to view this content.
    The paper clip icon does not work for attachments. Instead, under the text box where you type your reply click the Go Advanced button. On the next screen scroll down and click on Manage Attachments, which will show a pop-up window to Select and Upload a file. Then close the window.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    09-26-2018
    Location
    London
    MS-Off Ver
    O365 Plus
    Posts
    2

    Re: Type Mismatch when passing multi-dimensional array

    Thanks so much for the quick reply.

    In building up a set of dummy data for you to test it on; I think I found my error. It wasn't in passing the arrays back and forth - but in the second sub, the sub giving the error, I call a function that is expecting a string argument and tried to pass it a variant. I'm going to try convert that data when I pass it over and see if that solves the issue.

    Sorry for the waste of a post.

+ 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. Replies: 2
    Last Post: 04-23-2017, 12:04 AM
  2. Help converting one-dimensional array to multi-dimensional array
    By puzzlelover22 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2016, 06:48 AM
  3. [SOLVED] Passing array to procedure gives type mismatch error
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-14-2015, 08:10 AM
  4. [SOLVED] ByRef argument type mismatch / Passing array as a function argument
    By pzling in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-29-2012, 06:23 PM
  5. Error passing element of string array get ByRef argument type mismatch
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-17-2011, 02:59 PM
  6. Passing Multi-Dimensional Arrays
    By dldecler in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-28-2011, 02:03 PM
  7. Multi-Level Array Type Mismatch Error
    By CrazyFileMaker in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-04-2009, 06:20 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