How to get unique sorted indices of a list?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,687
Office Version
  1. 365
Platform
  1. Windows
Is there a way to get a set of unique (integer) indices into a list of numbers with no duplicates?

In this minisheet, the Values row has the list of numbers. There are duplicates. There are 2 2's and 3 3's.

The Rank.Eq row has the sorted indices, but there are duplicates. The Rank.Avg has the sorted indices, but there are fractions and duplicates. The Solution row has the indices I would like to get, but I would also be happy with the alternate indces on the next row. Is there a way to get it?

Sorting.xlsx
BCDEFGHIJ
8Values36231283
9Rank.Eq32638613
10Rank.Avg426.5486.514
11Solution47251386
12/5/6/3/4/6/2/4/5
Sheet2
Cell Formulas
RangeFormula
C9:J9C9=RANK.EQ(Values,Values)
C10:J10C10=RANK.AVG(Values,Values)
Named Ranges
NameRefers ToCells
Values=Sheet2!$C$8:$J$8C9:J10


Thanks
 

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.
One suggestion Jennifer, a bit clunky but seems to match your desired result.
Book1
BCDEFGHIJ
8Values36231283
9Rank.Eq32638613
10Rank.Avg426.5486.514
11
12Solution47251386
13Solution47251386
14/5/6/3/4/6/2/4/5
Sheet2
Cell Formulas
RangeFormula
C13:J13C13=RANK(C8,Values,1)+COUNTIF($C$8:C8,C8)-1
Named Ranges
NameRefers ToCells
Values=Sheet2!$C$8:$J$8C13:J13
 
Upvote 0
One suggestion Jennifer, a bit clunky but seems to match your desired result.
Hey, clunky is good if it works and anything more elegant is not available. 🤔🙄🤪

Thank you

I updated it to make use of the named range, but I couldn't figure out how to replace that $C$8.

Sorting.xlsx
BCDEFGHIJ
8Values36231283
9Rank.Eq32638613
10Rank.Avg426.5486.514
11Solution47251386
12/5/6/3/4/6/2/4/5
13kevin47251386
14kevin'47251386
Sheet2
Cell Formulas
RangeFormula
C9:J9C9=RANK.EQ(Values,Values)
C10:J10C10=RANK.AVG(Values,Values)
C13:J13C13=RANK(C8,Values,1)+COUNTIF($C$8:C8,C8)-1
C14:J14C14=RANK.EQ(@Values,Values,1)+COUNTIFS($C$8:@Values,@Values)-1
Named Ranges
NameRefers ToCells
Values=Sheet2!$C$8:$J$8C13:J14, C9:J10
 
Upvote 0
I'm sorry. I guess I have my head on backwards. What I need is list of indices into the Values list that will let me access them in ascending order. I want to be able to step through the Solution row and access the value in the Values row at that index. This values I will access will be in the order in the Result row. I will step through the Solution row using each index to access a value in the Values row. I will first select Solution(1)=5 and use it to access Values(5)=1. Then I'll select Solution(2=3 and use that to access Values(3)=2. Does that make any sense?

I will be doing this in VBA, so the Values will be an array and I can use the Solutions number as indices.

Sorry for the confusion. 😯😖

Sorting.xlsx
BCDEFGHIJ
7Index12345678
8Values36231283
9Rank.Eq32638613
10Rank.Avg426.5486.514
11Solution53614827
12Result12233368
Sheet2
Cell Formulas
RangeFormula
C9:J9C9=RANK.EQ(Values,Values,0)
C10:J10C10=RANK.AVG(Values,Values)
Named Ranges
NameRefers ToCells
Values=Sheet2!$C$8:$J$8C9:J10
 
Upvote 0
What I need is list of indices into the Values list
How do you currently get those values?

I think I'm starting to lose track of what it is exactly that you're looking for Jennifer. The way you describe the VBA part of your project is straightforward enough and I know well within your abilities - so is it purely a means of generating the Values list you're after? If so, I'm not sure what exactly they're representing :unsure:
 
Upvote 0
How do you currently get those values?

I think I'm starting to lose track of what it is exactly that you're looking for Jennifer. The way you describe the VBA part of your project is straightforward enough and I know well within your abilities - so is it purely a means of generating the Values list you're after? If so, I'm not sure what exactly they're representing :unsure:
The values can be a few different things. It can be frequencies or tallies. I am writing some code to be used by another party. It will be their data, so I have little control over what it is. My code needs to go through their list of values in acscending order. It will calculate some probabilities. Maybe something like this.

Sorting.xlsx
BCDEFGHIJ
8Values36231283
9Prob0.0710.0040.1770.0710.4270.1770.0000.071
Sheet2


I can demand that they sort the list before calling my code, but I thought it would be more general if I could handle unsorted data.

I could do the sort in my code, but I would need to write out the results in the original order.

Is that clear? I need a way to generate the Solution row below or equivalent in VBA so that stepping through it, I see the values in the Result row.

Sorting.xlsx
BCDEFGHIJ
7Index12345678
8Values36231283
9Prob0.0710.0040.1770.0710.4270.1770.0000.071
10Solution53614827
11Result12233368
Sheet2
 
Upvote 0
I understand what you're looking for now Jennifer, unfortunately I can't think of a solution at present. Need a clear head on this tomorrow. ;)
 
Upvote 0
I understand what you're looking for now Jennifer, unfortunately I can't think of a solution at present. Need a clear head on this tomorrow. ;)
OK, thanks for trying. I feel less useless is someone, like you, who came up with the other clever solution is also having difficulty.
 
Upvote 0
Here's another minisheet that might make it clearer. Row 7 is just for illustration. It contains the indices of the values. Row 8 contains the values. Row 9 contains the solution I would like to find. Row 10 shows that using Row 9, I can access the values in ascending order.

Sorting.xlsx
BCDEFGHIJ
7Index12345678
8Values36231283
9Solution wanted53614827
10Access via solution12233368
Sheet2
Cell Formulas
RangeFormula
C10:J10C10=INDEX(Values,1,C9)
Named Ranges
NameRefers ToCells
Values=Sheet2!$C$8:$J$8C10:J10
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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