[VBA] Sorting Values but Referencing Original Position (without index-match)

KyleX

New Member
Joined
Jul 11, 2017
Messages
14
Hello everyone.

For simplicity, I have a VBA loop which changes the range of cells being referenced during each iteration. For each loop I'm trying to find the largest 10 values and smallest 10 values from the range. The tricky part is I need to reference where those values are located in the range, because I need to start with the largest value and pair it with the smallest value that is also before this large value, and do this 10 times. So I need to find largest/smallest 10 values, but their "location" is important, even more so because after I find them, I need to edit a cell in the same row as the selected, acceptable values.

Hopefully this makes sense!

Now I could just take the range and use large and small functions like so:
Code:
 WorksheetFunction.Large

Buuuut, I'll probably have to reference position with index-match or something, and if 2 large or small values are the same (will happen), I'll only reference one location for 2 distinct values. So what I think would be ideal, is to set each cell in the range to a collection or array and sort it. I like this idea, but I still want some way to reference the original position in the range even after I sort it, without having to do index-match or something with the same flaws. I know in collections you can use keys, but I also know sorting in collections is a whole nother mess and I'm trying to run this loops hundreds of time, so efficiency is important. Any ideas, such as a way to get around the flaws with index-match, or using collections or arrays?

Examples would be awesome. Thanks in advance to any responses!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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