+ Reply to Thread
Results 1 to 13 of 13

VBA to store rows in different arrays based on cell values

  1. #1
    Registered User
    Join Date
    07-31-2018
    Location
    Copenhagen
    MS-Off Ver
    2013
    Posts
    30

    VBA to store rows in different arrays based on cell values

    Dear all,

    Thank you for helping out. I have searched the forum for other threads that could assist, but did not find any, so here we go.

    I have an Excel workbook with 6 different macros. Each macro searches row by row to find values, and with each hit it copies the row to the correct sheet.

    An example of such macro:

    Please Login or Register  to view this content.
    Because of roughly 60,000 rows, this coding is slow, and crashes often. And, to add to that, I have 6 different macros that copies to 6 different sheets based on different criterias. E.g. Criteria1 to 10 goes to sheet1, Criteria11 to 15 goes to sheet2 and so on.

    Therefore, my question is if it is possible to create an array instead? (other ideas are also more than welcome).

    I was hoping that it would then be possible to do the following through 2 macros:

    Macro 1:
    Loop through all rows and store rows with Criteria1 to Criteria10 in Array1, Criteria11 to Criteria15 in Array2, Criteria16 to Criteria20 in Array3 and so on.

    Macro 2:
    Copy all rows from Array1 into sheet1
    Copy all rows from Array2 into sheet2
    and so on.

    Thank you so much in advance. I am new to the array functions, and would really appreciate some help.

    Kr Anders

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

    Re: VBA to store rows in different arrays based on cell values

    Quote Originally Posted by AndersThyme View Post
    Loop through all rows and store rows with Criteria1 to Criteria10 in Array1, Criteria11 to Criteria15 in Array2, Criteria16 to Criteria20 in Array3 and so on.
    *Criteria1* should include Criteria10 to Criteria19, Criteria100 to Criteria199 etc.

    So, I don't think your code work properly.

  3. #3
    Registered User
    Join Date
    07-31-2018
    Location
    Copenhagen
    MS-Off Ver
    2013
    Posts
    30

    Re: VBA to store rows in different arrays based on cell values

    Hi Jindon,

    Sorry, that is my bad for choosing a bad example.
    I have changed the actual criterias due to not being able to share the originals.

    But the criterias will be changed to actual values, which could be e.g. names: "*Anders*", "*John*" and so on.

    Kr Anders

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

    Re: VBA to store rows in different arrays based on cell values

    Then need to see how the list of criteria constructed, but I guess AdvancedFilter would be the way.

  5. #5
    Registered User
    Join Date
    07-31-2018
    Location
    Copenhagen
    MS-Off Ver
    2013
    Posts
    30

    Re: VBA to store rows in different arrays based on cell values

    Hi again,

    I could not find out to do advanced filters for this search, since I do not have the exact values, but have to search on a "contains" level. E.g. the value might be "AndersMark" but should be found searching for "*Anders*" only.

    The current working (slow) macros:

    Macro1:

    Please Login or Register  to view this content.
    Macro2:
    Please Login or Register  to view this content.

    Macro3:

    Please Login or Register  to view this content.
    Macro4:

    Please Login or Register  to view this content.
    Macro5:

    Please Login or Register  to view this content.
    Macro6:

    Please Login or Register  to view this content.
    Last edited by AndersThyme; 09-25-2019 at 07:00 AM.

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

    Re: VBA to store rows in different arrays based on cell values

    Looping 60,000 rows would take time.
    You can use AdvancedFilter with the wild card for multiple criteria in one go.
    If you upload a small sample workbook with the criteria, I can show you how.

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  7. #7
    Registered User
    Join Date
    07-31-2018
    Location
    Copenhagen
    MS-Off Ver
    2013
    Posts
    30

    Re: VBA to store rows in different arrays based on cell values

    Hi again,

    Thank you for all the help, I really appreciate it.

    I have attached an example where the code I use currently is in, and is working (see Module 1). So you can see what the desired output is but running the macros (I have already run all the macros, to have the desired output shown in the different sheets).

    I hope that gives the best overview :-)

    Kr Anders
    Attached Files Attached Files

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

    Re: VBA to store rows in different arrays based on cell values

    See if this runs faster.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-31-2018
    Location
    Copenhagen
    MS-Off Ver
    2013
    Posts
    30

    Re: VBA to store rows in different arrays based on cell values

    Hi Jindon,

    Wow, it works like a charm on the test sheet.
    I will update it with 'sensitive' data and test it on the full data set and get back to you to confirm if it works.

    Kr Anders

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

    Re: VBA to store rows in different arrays based on cell values

    OK.
    As you can see each elements in an array consists of Array.

    e.g
    Please Login or Register  to view this content.
    1st element which is Array of criteria, Array("*John*", "*Niels*")
    and the 2nd element, "John" is a sheet name to correspond to.

  11. #11
    Registered User
    Join Date
    07-31-2018
    Location
    Copenhagen
    MS-Off Ver
    2013
    Posts
    30

    Re: VBA to store rows in different arrays based on cell values

    Hi Jindon,

    I have now tested it with >55,000 rows and it works perfectly. It has reduced the time from 15-20 minutes to take < 1 minute.

    Thank you for the patience, the help and the very useful outcome. It is really appreciated.

    Kr Anders

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

    Re: VBA to store rows in different arrays based on cell values

    You are welcme and thanks for the rep.

    It would help to speed up if you set Application.ScreenUpdating = False and True at the end. e.g
    Please Login or Register  to view this content.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  13. #13
    Registered User
    Join Date
    07-31-2018
    Location
    Copenhagen
    MS-Off Ver
    2013
    Posts
    30

    Re: VBA to store rows in different arrays based on cell values

    Thank you 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. Replies: 1
    Last Post: 12-09-2018, 10:32 AM
  2. Rewrite VBA script from Column based arrays to Rows based arrays
    By wtell319 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-11-2018, 09:24 AM
  3. [SOLVED] Store multiple arrays in one array
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-12-2017, 01:31 AM
  4. [SOLVED] Dynamic Changing Data, Based on Criteria Store in Array, Sum array and store in Cell
    By penbeacho in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-28-2015, 10:31 AM
  5. VBA store references with arrays
    By fuatt in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-25-2013, 07:57 AM
  6. [SOLVED] Store Column A & B values in separate arrays for every unique value in Column A
    By tenscourts in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-30-2012, 09:53 AM
  7. seprate and store string in arrays
    By ilyaskazi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-29-2005, 10:22 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