Consulting

Results 1 to 2 of 2

Thread: VBA Dynamic array

  1. #1

    VBA Dynamic array

    I'm having a nightmare simply trying to define a dynamic array and write data to it.

    Basically I have the following :-

    Where y is already defined as the function and updates as the function is called. I want to add the y value to an array so I can fix the max value of y when the function reaches the end i.e. no more updates.

    y As Integer,


    Dim Arr1() as variant

    Arr1() = y



    Doesn't work , saying compile error can't assign to an array.

    Any suggestions ?
    Last edited by cblake843; 11-29-2018 at 04:24 AM.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Dim Arr1() as Variant is a dynamic array, i.e. no upper/lower bounds yet

    Also, you can't assign a variable to an array

    Dim Arr1() as Variant ReDIm Arr1(0 to 99) Arr1(27) = y

    No other ideas without know more about what is going on

    More information will get better ideas
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

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