+ Reply to Thread
Results 1 to 10 of 10

Help with Declaring a dynamic 2 dimensional array

  1. #1
    Registered User
    Join Date
    12-30-2014
    Location
    Dublin Ireland
    MS-Off Ver
    2007
    Posts
    12

    Help with Declaring a dynamic 2 dimensional array

    Hi Guys,

    I am trying to declare a 2 dimensional array and have written the below code. the problem I have is that the upper bound I declare results in an array that is too big as I only want the rows that have cell (i,9) as purchases or redemptions (this needs to be amended first). I think I need to declare a dynamic array (as the rows could change) but I don't know how to do this with a two dimensional array. Any help is greatly appreciated

    Please Login or Register  to view this content.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help with Declaring a dynamic 2 dimensional array

    Please Login or Register  to view this content.
    Last edited by shg; 01-29-2015 at 03:37 PM.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    12-30-2014
    Location
    Dublin Ireland
    MS-Off Ver
    2007
    Posts
    12

    Re: Help with Declaring a dynamic 2 dimensional array

    Thanks shg

    Looking at your post I assumed you meant declare the transarray as variant and then redim in the loop but this doesnt seem to work, if I put the Redim statement in the loop I am still left with a few thousand extra rows in the array with no data. I then tried the below and I got a type mismatch error when the code is populating the array

    Please Login or Register  to view this content.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help with Declaring a dynamic 2 dimensional array

    No, I meant what I posted. finalrow is neither declared nor initialized in your code. The code needs other changes, but start with that. And putting Option Explicit at the top of the code module.

  5. #5
    Registered User
    Join Date
    12-30-2014
    Location
    Dublin Ireland
    MS-Off Ver
    2007
    Posts
    12

    Re: Help with Declaring a dynamic 2 dimensional array

    Sorry mate Im pretty new to VBA just bear with me. I've made changes below -


    Please Login or Register  to view this content.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help with Declaring a dynamic 2 dimensional array

    Better, good job. How's that working for you?

  7. #7
    Registered User
    Join Date
    12-30-2014
    Location
    Dublin Ireland
    MS-Off Ver
    2007
    Posts
    12

    Re: Help with Declaring a dynamic 2 dimensional array

    Yeah it works better but the array's size is the same as the whole sheet (5000 rows). I want just the rows that have "purchases" or "redemptions" in (i,9) to determine the arrays size and then fill it under the 5 headings(6,5,9,19,16). There are around 1000 of these rows and when the array is currently filled it has around 4000 sets of empty values
    Last edited by gablet; 01-29-2015 at 07:13 PM.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help with Declaring a dynamic 2 dimensional array

    Maybe ...

    Please Login or Register  to view this content.
    Last edited by shg; 02-01-2015 at 03:19 PM.

  9. #9
    Registered User
    Join Date
    12-30-2014
    Location
    Dublin Ireland
    MS-Off Ver
    2007
    Posts
    12

    Re: Help with Declaring a dynamic 2 dimensional array

    That works great thanks shg

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help with Declaring a dynamic 2 dimensional array

    You're welcome.

+ 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] Add to a two dimensional dynamic array based on a condition - redim preserve
    By wazimu13 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-04-2014, 04:46 AM
  2. [SOLVED] Need help on Basic Two Dimensional Dynamic Array
    By chrixton in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-02-2014, 08:07 PM
  3. Dynamic 2 dimensional array in VBA class
    By dlx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-21-2010, 09:20 PM
  4. Declaring Multi-Dimensional Array
    By Phil_V in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-05-2008, 08:43 AM
  5. Declaring 2 dimensional array
    By sreerag446 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-15-2008, 09:29 AM

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