+ Reply to Thread
Results 1 to 4 of 4

VBA: Array of User Defined Type passed as parameter to function

  1. #1
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    VBA: Array of User Defined Type passed as parameter to function

    I've declared a User Defined Type as follows in Module 1:
    Please Login or Register  to view this content.
    Then inside a sub some array variables are declared as follows (in the same module):
    Please Login or Register  to view this content.
    These arrays are then populated with data. I now need to pass these arrays to another function that will combine some of the relevant data from each of the arrays and return me another array of the same UDT type e.g.:
    Please Login or Register  to view this content.
    However; There is some problem somewhere?

    I get the following error message:
    Compile error:

    Only user-defined types defined in public modules can be coerced to or from a variant or passed to late-bound functions.


    Any ideas what's wrong or how to do this?
    Last edited by Bezzie; 10-14-2013 at 07:02 AM. Reason: Typo fixed.

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: VBA: Array of User Defined Type passed as parameter to function

    I do not think this declaration is valid

    Please Login or Register  to view this content.
    When I change the type of variable C to string I do no longer receive any compilation errors
    If you like my contribution click the star icon!

  3. #3
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: VBA: Array of User Defined Type passed as parameter to function

    My bad, typing error. Must be c As Double.

  4. #4
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: VBA: Array of User Defined Type passed as parameter to function

    I'm an idiot!

    Sorry guys. The error was because of another line but I didn't notice. Just saw the Function Declaration highlighted and immediately assumed that's where the error was.

    My apologies.

+ 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] returning user-defined type in array from function?
    By onidarbe in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-17-2013, 05:45 PM
  2. Type Mismatch: array or user defined type expected
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-06-2006, 10:45 AM
  3. [SOLVED] User Defined type as Sub parameter?
    By plh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-27-2006, 12:20 AM
  4. [SOLVED] Help: Compile error: type mismatch: array or user defined type expected
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2005, 05:05 PM
  5. user defined function receiving a range as parameter
    By Marc in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-14-2005, 03: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