Turn macro into UDF with variable range

  • Thread starter Thread starter Legacy 505880
  • Start date Start date
Status
Not open for further replies.
L

Legacy 505880

Guest
Hello. Lately i've been trying to set up an udf which pulls numbers from indipendent lists so that all pulled numbers are different. An example might be A:[1,3], B:[3], C:[5,6,2], D:[1,2] and E[3,4,5,6]. a possible solution could be [1,3,5,2,6], or [1,3,6,2,4]. There can be more or less than 5 lists, this is just an example. Note that there are dependancies between lists. For example, 3 can't be pulled from A because otherwise it won't be possible to pull a number from B. So far i found a couple functions that fit my needs, while also being fairly fast, considering this can be a really long task for a machine. However, these are macros and i'd need them to be udfs for a series of reasons. first, because i need the function to recalculate whenever i press f9 on the spreadsheet, i don't want the solution to stay the same. I also need to change the range whenever i want to (in the case of the example i gave you, the udf input would be A1:E4). The third reason is that i need the solution to be an array with each number in a different cell. In the second macro i will give you, the code also returns the amount of seconds it takes to calculate, which is completely irrelevant to me, so you can remove it.


Thank you in advance, feel free to ask me questions for more clarity on the problem
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Status
Not open for further replies.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top