+ Reply to Thread
Results 1 to 5 of 5

Find position in an array, need to improve the performance

  1. #1
    Registered User
    Join Date
    10-29-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    17

    Find position in an array, need to improve the performance

    Hello all,

    How can I improve the performance of the code below. I got two array DestArray and strArray. I would like to check if all numbers in DestArray exist in strArray and get the position in the strArray if it exist.

    / P


    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Find position in an array, need to improve the performance

    You're looking for the index of every item in DestArray in strArray? You're not doing anything with them? That is, you're not storing them separately?

    You want exact matches? Even if so, if strArray were relatively large, better to sort it in ascending order. Then change your loop to

    CORRECTION

    Please Login or Register  to view this content.
    Last edited by hrlngrv; 09-29-2020 at 04:46 PM.

  3. #3
    Registered User
    Join Date
    10-29-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Find position in an array, need to improve the performance

    Thanks for the replay! Yes I would like to check if all numbers in the DestArray exist in strArray. I will pull out data from the DestArray that is why I would like to get the row number. The DestArray is quite big around 130000 rows.

    I could not get the code to be faster with your code? Maybe I did something wrong.

  4. #4
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Find position in an array, need to improve the performance

    Is strArray sorted in ascending order?

    If there could be duplicates in DestArray, you may want to sort it too, then check if the i_th value equals the (i-1)_th value, and if so you already have the index in strArray.

    Sorting and binary search are the only ways to speed up operations like this.

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

    Re: Find position in an array, need to improve the performance

    Quote Originally Posted by Per_ View Post
    The DestArray is quite big around 130000 rows.
    Loop with a dictionary object would be faster
    e.g
    assuming strArray is a single dimensional array,
    Please Login or Register  to view this content.
    Last edited by jindon; 09-30-2020 at 03:16 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. Nine Quick Tips to Improve VBA Performance
    By alansidman in forum Tips and Tutorials
    Replies: 3
    Last Post: 05-24-2022, 03:11 AM
  2. Improve performance
    By twister889 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-17-2020, 03:08 PM
  3. Replies: 5
    Last Post: 03-29-2017, 02:08 AM
  4. [SOLVED] Can VBA improve the performance of this spreadsheet
    By gassiusmax in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-29-2014, 05:19 AM
  5. [SOLVED] Find Data in one array and match the position in another array
    By zeeman2 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-27-2013, 07:55 PM
  6. improve performance
    By david90 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-28-2013, 01:12 AM
  7. How to improve the performance of a looping UDF
    By johnnycanuck in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-03-2011, 01:39 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