+ Reply to Thread
Results 1 to 8 of 8

Redim Preserve multidimensional array not working

  1. #1
    Forum Contributor
    Join Date
    07-23-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    211

    Redim Preserve multidimensional array not working

    Hi

    I have the following code to transfer a selection of data from one worksheet ("All SAP Data") to another worksheet ("M&T Data only").

    The "All SAP Data" has over 50k rows and 16 columns of data. Column 14 contains reference codes such as 6050, 6054, 6067, 6155 etc. (there are about 35 reference codes to select from).

    I want to loop down each row of data in "All SAP Data" and if that row contains 6050 in column 14, transfer data in that row from columns 5, 7, 9, 10, 11, 12 and 14 to "M&T Data only".

    Eventually, I will be wanting to select a number of reference codes, say 6050, 6067, 6155 etc. (up to 10) but for the time being I was testing this only for 6050.

    The code I have is:

    Please Login or Register  to view this content.
    I get a type Subscript out of range error at this point:

    Please Login or Register  to view this content.
    Could someone point out why it's doing that please?

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Redim Preserve multidimensional array not working

    aDataIn only has 2 dimensions therefore Ubound(aDataIn, 7) will not work. I do not understand why you use Preserve if there is no data in aDataOut to preserve, but if you use this you may only resize the last dimension of aDataOut.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  3. #3
    Forum Contributor
    Join Date
    07-23-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    211

    Re: Redim Preserve multidimensional array not working

    Hi Izandol

    Many thanks for replying. I am not confident with arrays and have adapted the code which works for a 1D array to deal with a 2D array. Would you be able to guide me how to deal with a 2D array?

  4. #4
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Redim Preserve multidimensional array not working

    I have not tested this:
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-23-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    211

    Re: Redim Preserve multidimensional array not working

    Izandol

    Your suggestion stopped the error. However, I think my output code must be wrong because it is only printing the first 7 rows as follows:

    Capture.PNG

    The output code is :

    Please Login or Register  to view this content.
    Thanks again for helping me progress. What could be going wrong with my code?

  6. #6
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Redim Preserve multidimensional array not working

    Please check the output code in my version. You do not want to transpose, and your row count is incorrect because of your header row.

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Redim Preserve multidimensional array not working

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    07-23-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    211

    Re: Redim Preserve multidimensional array not working

    So sorry about the delay in coming back, Izandol...your code worked perfectly and read through all the data and processed it within 1 sec!! Fantastic. Many thanks for your help.

    AB33, your code worked just as well. Thanks for this.

    Wow...what a fantastic Forum!

+ 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] Dynamic Array Fails to Redim Preserve
    By rodalsa1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-07-2013, 09:52 AM
  2. Using the ReDim array function in a multidimensional array in excel
    By Doruli in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-05-2012, 01:43 PM
  3. redim preserve multidimensional array
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-07-2011, 02:48 PM
  4. Redim Preserve 2D Array
    By kraljb in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-12-2006, 03:23 PM
  5. how to redim more than one dimension in a multidimensional dynamic array?
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-28-2005, 06: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