+ Reply to Thread
Results 1 to 10 of 10

VBA - Array - Two Dimensional Array Issue

  1. #1
    Registered User
    Join Date
    04-26-2019
    Location
    Australia
    MS-Off Ver
    365 ProPlus
    Posts
    13

    VBA - Array - Two Dimensional Array Issue

    Hi,

    I have two columns of data that I want to extrapolate out but struggling to get the final bit of code to complete it.

    I understand running this as an array will be the best option as the final row count once completed will be over 100,000.

    In a basic example I have 3 rows of data in column A and 2 rows of data in column B. eg:

    A B
    Apple Farm
    Orange House
    Banana

    The number of rows for the final product will be 6 (3 x2)
    The final outcome should look like this, Where each A should be linked to a B:

    A B
    Apple Farm
    Apple House
    Orange Farm
    Orange House
    Banana Farm
    Banana House

    My code so far is:

    HTML Code: 
    Do I need a For Each element in arrLoc type of situation to loop this?
    I tried various things but obviously they were off the mark, and I am sure the solution is probably easier than I think. Maybe I am overthinking it becuase it's an array.

    Any help to complete the loop would be most appreciated.

    Also, for the actual data I am using the final result could be between 100 and 200k rows. Will an array hold that much information and if so will this still take a very long time to process?

    Thanks very much.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: VBA - Array - Two Dimensional Array Issue

    For counter loop
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-26-2019
    Location
    Australia
    MS-Off Ver
    365 ProPlus
    Posts
    13

    Re: VBA - Array - Two Dimensional Array Issue

    Jindon,

    that is perfect, thank you so much.

    I will sit down and study this line by line and understand it, but in the meantime it does the trick.

    Are there any size/row limitations on this?

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: VBA - Array - Two Dimensional Array Issue

    Please Login or Register  to view this content.
    Limit will depends on memory of your machine, and when size exceeds the number of rows in Excel, you will get run time error.

    If this takes a lot of time in you actual data size, MS Query would be the second consideration.

  5. #5
    Registered User
    Join Date
    04-26-2019
    Location
    Australia
    MS-Off Ver
    365 ProPlus
    Posts
    13

    Re: VBA - Array - Two Dimensional Array Issue

    Thanks for the updated code with comments.
    This only appears to work for the 3x2 example I gave you, if I fill in one more cell in either A or B then I get a Run Time error 9.
    It looks like your code should pick up the current region despite the number of rows filled in, however this doesn't seem to happen. I appear to be locked in to the 3x2 matrix only.
    Is this an issue my end where the current region is not refreshing or not being read correctly?

  6. #6
    Registered User
    Join Date
    04-26-2019
    Location
    Australia
    MS-Off Ver
    365 ProPlus
    Posts
    13

    Re: VBA - Array - Two Dimensional Array Issue

    Just an additional note to the above ... looks like I am maxxed out at having 2 values in column B but unlimited in A.
    Does the following restrict this: ReDim b(1 To UBound(a, 1) * UBound(a, 2), 1 To 2)?
    The error appears in: b(n, 1) = a(i, 1): b(n, 2) = a(ii, 2)

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: VBA - Array - Two Dimensional Array Issue

    Try change to
    Please Login or Register  to view this content.
    Im out at the momemt, so there might be typo etc,

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: VBA - Array - Two Dimensional Array Issue

    Oops, it is not that line.

    should be

    redim b(1 to ubound(a,1) ^ 2, 1 to 2)

    fixed a typo.
    Last edited by jindon; 05-10-2019 at 02:50 AM.

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,487

    Re: VBA - Array - Two Dimensional Array Issue

    Try this

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  10. #10
    Registered User
    Join Date
    04-26-2019
    Location
    Australia
    MS-Off Ver
    365 ProPlus
    Posts
    13

    Re: VBA - Array - Two Dimensional Array Issue

    Thanks Andy,

    That is exactly what I am after, goes the trick perfectly.
    I need to familiarize myself more in how to use Resize correctly.

    Thanks again

+ 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] have 1 dimensional array, trying to create a 2 dimensional array, runtime 9
    By dmcgov in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-21-2019, 07:03 AM
  2. [SOLVED] Storing Array to Find Replace Value via 2 Dimensional Array
    By Matty5894 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-19-2016, 05:53 AM
  3. Help converting one-dimensional array to multi-dimensional array
    By puzzlelover22 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2016, 06:48 AM
  4. Parse Data from one dimensional array into a 2 dimensional array.
    By JapanDave in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-30-2016, 07:29 AM
  5. Replies: 6
    Last Post: 09-25-2013, 10:08 PM
  6. Populate a Single Dimensional Array with two Dim Array (matrix)
    By Benjamin1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-03-2011, 12:49 PM
  7. Mutli-dimensional Array to Single-Dimension Array
    By Blue Aardvark in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-15-2005, 05:05 AM

Tags for this Thread

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