+ Reply to Thread
Results 1 to 8 of 8

Split Array into an Unknown Number of Separate Arrays

  1. #1
    Registered User
    Join Date
    03-03-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Split Array into an Unknown Number of Separate Arrays

    I have a list of names in column A on sheet 1.
    Upon running a sub, those names are placed into an array, shuffled into a random order and then put back into sheet 1 column a in their new order.
    What I now want to do is evenly split the array values by a number that the user enters via an input box and for these to be placed in their own array.

    i.e. If I have a have a list of 100 names and the user enters 4 after being prompted, 4 different arrays would be created with 25 elements in each.
    Similarly, if the user inputs 5 then 5 different arrays are created with 20 elements in each.

    I do not mind in terms of naming conventions for the arrays. I guess something like arr1, arr2, etc would be easiest but I just can't figure out how to do this!

    Any help would greatly be appreciated.

    Here is my code so far:
    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Split Array into an Unknown Number of Separate Arrays

    without array
    Please Login or Register  to view this content.
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    03-03-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Split Array into an Unknown Number of Separate Arrays

    Thank you for the response but unfortunately I need to do this without manipulating data on the worksheet.
    At the moment I am putting the randomly sorted array values back on the worksheet but this is just for testing purposes.
    Eventually (hopefully) all the manipulation will be done is the memory.
    I need the x number of different arrays as each of them will be used to populate an email body.

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Split Array into an Unknown Number of Separate Arrays

    why do you need the x number of different arrays ? why not an array with many columns ? you can manage with the index also a simple one dimension array
    Last edited by patel45; 09-14-2013 at 07:13 AM.

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Split Array into an Unknown Number of Separate Arrays

    Here you are:

    Please Login or Register  to view this content.



  6. #6
    Registered User
    Join Date
    03-03-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Split Array into an Unknown Number of Separate Arrays

    Thank you all for you help.
    Ideally I do not want to manipulate or change the data on the worksheet in anyway - I want it all to take place in the memory.
    This is because there are vast amounts of data in the worksheet (I have simplified my question to make the concept easier to understand).
    I could split the array across multiple columns in a new worksheet, collect the data I need and then delete the worksheet but ideally I don't want to do this.
    I suppose I could use a 2d array and then I could just reference a specific column within that array.

    Can anyone advise me on how I go about setting the number of columns in the array dynamically (based on a user input) and then split the values across each of the array columns evenly?

    Once again, thanks everyone for their help so far.

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Split Array into an Unknown Number of Separate Arrays


  8. #8
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Split Array into an Unknown Number of Separate Arrays

    Please Login or Register  to view this content.
    Snb
    your code is very efficient, but not easy to understand, i'm sorry but I did not realize you had solved
    Last edited by patel45; 09-14-2013 at 11:10 AM.

+ 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] Split Array, Listing Marked Items in Split Arrays
    By lesoies in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-27-2013, 02:07 AM
  2. Unknown number of arrays as argument to VBA function
    By Huugin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-03-2012, 05:30 PM
  3. Replies: 2
    Last Post: 05-06-2011, 09:14 AM
  4. Separate One Array Into Multiple Small Arrays
    By redan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-20-2008, 07:27 AM
  5. Split Number into Four Separate Parts
    By Gos-C in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-16-2005, 02:08 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