Consulting

Results 1 to 4 of 4

Thread: Solved: Transfer data from Array declared with Userdefined Type variable to Excel

  1. #1
    VBAX Regular
    Joined
    Dec 2007
    Posts
    17
    Location

    Solved: Transfer data from Array declared with Userdefined Type variable to Excel

    I have declared a Userdefined Type array:

    [vba]
    Option Explicit
    Option Private Module

    Private Const iMAX_CONTROL_PROPERTIES As Integer = 500

    Private Type FORM_TRANSLATION_PARAMS
    sKeyID As String
    sFormName As String
    sControlType As String
    sControlName As String
    sControlItem As String
    sTransText As String
    End Type

    Public aTransTable(1 To iMAX_CONTROL_PROPERTIES) As FORM_TRANSLATION_PARAMS
    [/vba]

    This array is used in a subroutine that loops through all the UserForms in a project and captures some of the properties of some of the controls on these forms.

    Once all UserForms have been processed, I want to store the contents of the array in an Excel range.
    I know how to do this with an ordinary array (meaning non-Userdefined type as variable). However, the standard way to do this, does of course not apply for the Userdefined Type I use for my array. This because a single item of the array, e.g. aTransTable(1) does not store one single value but 6 values:

    [vba]
    aTransTable(1).sKeyID
    aTransTable(1).sFormName
    aTransTable(1).sControlType
    aTransTable(1).sControlName
    aTransTable(1).sControlItem
    aTransTable(1).sTransText[/vba]

    Now of course I could do any of the following things to resolve my problem:
    1. Rewrite my code and not use a Userdefined Type for my array, but use a standard 2D variable for the array;

      or,
    2. After the Userdefined Type array has been filled with data, transfer the contents to a new standard 2D array, which I can easily write to an Excel range.
    Before I do that, I just wanted to run this by you to see if I might be overlooking something, and I actually can transfer the data from my original (Userdefined Type) array directly to an Excel range.

    Any ideas?
    Last edited by BenD; 01-04-2008 at 03:35 AM. Reason: Solved
    Cheers,

    Ben

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    No, I would just use a 2D array?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Dec 2007
    Posts
    17
    Location
    That is already what I thought, so thanks for confirming xld!
    Cheers,

    Ben

  4. #4
    VBAX Regular
    Joined
    Dec 2007
    Posts
    17
    Location
    That is already what I thought, so thanks for confirming xld!
    Cheers,

    Ben

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •