+ Reply to Thread
Results 1 to 13 of 13

Select different numbers from indipendent lists efficiently

  1. #1
    Registered User
    Join Date
    02-20-2023
    Location
    rome
    MS-Off Ver
    office 2021
    Posts
    15

    Select different numbers from indipendent lists efficiently

    Hello everybody. I'm looking for a volatile UDF that selects a random entry from every column in a given range so that every selected value is unique. The same numbers can appear in multiple columns, but not more than once in a column. As i stated, the UDF needs to update whenever i refresh the worksheet, wheter or not the input numbers change. The input parameter would be the data range (e.g. If the starting data was A:[1,2,5], B:[6,3,2], C:[4,5,6,7], D:[6], E:[3,7,8] the UDF's input would be A1:E4, so note that the input contains empty cells too) and the output would be an array containing a random solution (e.g. [1,3,7,6,8] or [3,2,4,6,7], with the previous data). The UDF needs to take an optimised path, otherwise it's going to be very slow with large datasets. This is probably the hardest part, which is why i asked for help in this forum.
    Here is a sample to better understand the problem: samples.xlsm. My datased is substantially larger than this, which is why i need an efficient method.
    --to the moderators, I'm aware that i've already asked this on another thread and other forums but the answer i got is giving issues so I posted again to state the problem more clearly and hopefull receive new answers. Please don't take this down, thank you--
    Last edited by MrBlonde_; 04-30-2023 at 04:43 PM.

  2. #2
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Select different numbers from indipendent lists efficiently

    see sheet "blad1", 1.000 rows and 10 columns filled with random values 1-10.
    Output in columns M:V for those unique values, in column X the executiontime in secondes for 2 methods. (this time is sometimes too short)
    Attached Files Attached Files
    Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    02-20-2023
    Location
    rome
    MS-Off Ver
    office 2021
    Posts
    15

    Re: Select different numbers from indipendent lists efficiently

    how do i get rid of this part of the array Attachment 827607, keeping only the solution's numbers?. Other than that, the function works perfectly fine, this was incredibly helpful
    Last edited by MrBlonde_; 04-30-2023 at 07:41 PM.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,926

    Re: Select different numbers from indipendent lists efficiently

    Administrative Note:

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not told us about this. You are required to do so.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important: https://excelguru.ca/a-message-to-forum-cross-posters/

    (Note: this requirement is not optional. As a courtesy, I shall do it for you this time: https://www.mrexcel.com/board/thread...lumns.1235704/)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Registered User
    Join Date
    02-20-2023
    Location
    rome
    MS-Off Ver
    office 2021
    Posts
    15

    Re: Select different numbers from indipendent lists efficiently

    sorry, i wasn't getting a response on other forums and forgot to mention it in the opening message, my bad

  6. #6
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Select different numbers from indipendent lists efficiently

    invalid attachment in #3.
    There were 3 lines too much ...
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    02-20-2023
    Location
    rome
    MS-Off Ver
    office 2021
    Posts
    15

    Re: Select different numbers from indipendent lists efficiently

    Thank you. I have one last question. Would it be possible to modify the code for the UDF to still work with a formula that creates a 2D array (like the one that generates variable lists in the sample i gave) as the input?
    Last edited by MrBlonde_; 04-30-2023 at 08:46 PM.

  8. #8
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Select different numbers from indipendent lists efficiently

    like this ?
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    02-20-2023
    Location
    rome
    MS-Off Ver
    office 2021
    Posts
    15

    Re: Select different numbers from indipendent lists efficiently

    Yes. exactly like this. Is this as fast as the one you gave me previously?

  10. #10
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Select different numbers from indipendent lists efficiently

    I think it's even faster.
    My example with 1000 rows and 10 columns wasn't that good, because you said that every entry in a column is unique, but the columns have common numbers and the result has to have again unique numbers. If you have only 1 column with 1.000 records and the others for example only approx. 10, then i can better add some lines to speed that up.
    Attached Files Attached Files
    Last edited by bsalv; 05-01-2023 at 03:05 AM.

  11. #11
    Registered User
    Join Date
    02-20-2023
    Location
    rome
    MS-Off Ver
    office 2021
    Posts
    15

    Re: Select different numbers from indipendent lists efficiently

    Quote Originally Posted by bsalv View Post
    If you have only 1 column with 1.000 records and the others for example only approx. 10, then i can better add some lines to speed that up.
    So this is an improvement when these conditions are met. should I still use it instead of the previous you gave me (samples (12).xlsm) if i have 10 columns with 1000 rows each?

  12. #12
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Select different numbers from indipendent lists efficiently

    you can use the last one (#10) in all situations. Good luck.

  13. #13
    Registered User
    Join Date
    02-20-2023
    Location
    rome
    MS-Off Ver
    office 2021
    Posts
    15

    Re: Select different numbers from indipendent lists efficiently

    I can't thank you enough for this, really

+ 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. Multiselect lists on Mac will select with Alt key
    By gordonbe in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-31-2019, 07:32 AM
  2. Select different lists
    By jonhat in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-17-2018, 06:09 PM
  3. I need to compare 2 large lists of numbers and out put numbers that are in both lists.
    By imcquill09 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-21-2016, 02:57 PM
  4. Replies: 8
    Last Post: 11-19-2014, 06:12 PM
  5. Select from lists
    By Stevep4 in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 12-17-2008, 05:54 PM
  6. Comparing numbers in lists/columns of numbers
    By Onesimus in forum Excel General
    Replies: 3
    Last Post: 12-15-2007, 02:19 PM
  7. Replies: 4
    Last Post: 07-09-2007, 04:38 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