richard1234567891011

Board Regular
Joined
Feb 21, 2018
Messages
91
Hi guys, I need a rank formula, these are the data.

Screenshot-2019-08-09-at-16-59-32.png
[/URL][/IMG]

The expected result is in the green column. So, rank the same values in one (multiple values all equal the same), without jumps of numbers, and consider the different names in another rank (Pescara and Chieti). I need a formula in order to do this.

Thank you guys.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Maybe...

E2 copied down
=SUMPRODUCT(--(A$2:A$14<>A2),--(B$2:B$14>B2),--(MATCH(A$2:A$14,A$2:A$14,0)=ROW(A$2:A$14)-ROW(A$2)+1))+1+SUMPRODUCT(--(A$1:A1<>A2),--(B$1:B1=B2),--(MATCH(A$1:A1,A$1:A1,0)=ROW(A$1:A1)-ROW(A$1)+1))

M.
 
Upvote 0
Is there any reason that 375|PESCARA gets a rank of 2 and 375|CHIETI gets a rank of 3? Could it just as well be that 375|PESCARA gets a rank of 3 and 375|CHIETI gets a rank of 2?
 
Upvote 0
Is there any reason that 375|PESCARA gets a rank of 2 and 375|CHIETI gets a rank of 3? Could it just as well be that 375|PESCARA gets a rank of 3 and 375|CHIETI gets a rank of 2?

The only reason is that every name need a different rank (without repeating the same name and without jumps ranks) It is irrelevant if before there is Chieti o Pescara.
 
Upvote 0
The only reason is that every name need a different rank (without repeating the same name and without jumps ranks) It is irrelevant if before there is Chieti o Pescara.
OK, thanks.
I can't think of an easy way with standard worksheet formulas, but you could try this user-defined function. To implement ..

1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy down.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

Code:
Function RankSpecial(lValue As Long, sCity As String, rData As Range) As Long
  Static SL As Object
  Dim a As Variant
  Dim i As Long
  Dim s As String
  
  If SL Is Nothing Then Set SL = CreateObject("System.Collections.Sortedlist")
  a = rData.Value
  SL.Clear
  For i = 1 To UBound(a)
    s = 10 ^ 10 - a(i, 2) & "|" & a(i, 1)
    If Not SL.ContainsKey(s) Then SL.Add s, a(i, 2)
  Next i
  RankSpecial = SL.IndexOfKey(10 ^ 10 - lValue & "|" & sCity) + 1
End Function

Excel Workbook
ABC
1CityValueRank
2PESCARA3753
3PESCARA3753
4PESCARA3753
5CHIETI3752
6CHIETI3752
7CHIETI3752
8CHIETI3752
9CHIETI3752
10CHIETI3752
11CHIETI3752
12FARA IN SABINA2504
13COSSATO1005
14ALMENNO S.SALVATORE4001
Rank
 
Upvote 0
Try this in C2:

=IF(COUNTIFS($A$2:A2,A2,$B$2:B2,B2)=1,
SUM(IFERROR(1/COUNTIFS($A$2:$A$14,$A$2:$A$14,$B$2:$B$14,">"&B2),0))+SUM(IFERROR(1/COUNTIFS($A$2:A2,$A$2:A2,$B$2:B2,B2),0)),
VLOOKUP(A2,$A$1:C1,3,0))

Array formula, Enter with Ctrl+Shift+Enter.
 
Upvote 0
The result is #N/A. The formula, unfortunately is not working.

Result #N/A???? Don't understand how a formula using SUMPRODUCT can generate such result :confused:, unless there are errors or blank rows in your data. Check.

Worked perfectly for me...


A
B
C
D
E
1
City​
Value​
Rank​
2
PESCARA​
375​
2​
3
PESCARA​
375​
2​
4
PESCARA​
375​
2​
5
CHIETI​
375​
3​
6
CHIETI​
375​
3​
7
CHIETI​
375​
3​
8
CHIETI​
375​
3​
9
CHIETI​
375​
3​
10
CHIETI​
375​
3​
11
CHIETI​
375​
3​
12
FARA IN SABINO​
250​
4​
13
COSSATO​
100​
5​
14
ALMENO S. SALVATORE​
400​
1​

<tbody>
</tbody>


Formula in E2 copied down
=SUMPRODUCT(--(A$2:A$14<>A2),--(B$2:B$14>B2),--(MATCH(A$2:A$14,A$2:A$14,0)=ROW(A$2:A$14)-ROW(A$2)+1))+1+SUMPRODUCT(--(A$1:A1<>A2),--(B$1:B1=B2),--(MATCH(A$1:A1,A$1:A1,0)=ROW(A$1:A1)-ROW(A$1)+1))

M.
 
Last edited:
Upvote 0
Thank you guys,
Sorry if I answer now, I was some days in holiday.
Both formula made by Marcelo Branco and Phuoc are indeed working.
The only issue in both is that are not able to read blank cells. Do you think that is it possible to adjust the one formula in order to make it to read also blank cells? The issue is that my colleagues are not very skilled in excel and they will need to add data. New data will not be read in with both formulas.
Regarding the macro made by Peter_SSs, I am sure that it is correct, but the issue is the same, my colleagues are not skilled in excel, I don't want for this reason a macro inside.

Thank you very much guys.
 
Last edited:
Upvote 0
This scenario - multiple cities with the same value and different ranks - and adding the possibility of blank cells, requires a complex array formula. Would this be convenient for you? Or would it not be more practical to eliminate blank rows?

Anyway, try this formula ...


A
B
C
D
E
1
City​
Value
Rank​
2
PESCARA​
375
2​
3
PESCARA​
375​
2​
4
PESCARA​
375​
2​
5
6
CHIETI​
375​
3​
7
CHIETI​
375​
3​
8
CHIETI​
375
3​
9
CHIETI​
375
3​
10
CHIETI​
375​
3​
11
CHIETI​
375​
3​
12
CHIETI​
375​
3​
13
14
FARA IN SABINO​
250
4​
15
16
COSSATO​
100
5​
17
18
ALMENO S. SALVATORE​
400
1​
19
ALMENO S. SALVATORE​
400
1​

<tbody>
</tbody>


Array formula in E2 copied down
=IF(A2="","",IF(COUNTIF(A$2:A2,A2)=1,SUM(IF(FREQUENCY(IF(A$2:A$100<>"",MATCH(A$2:A$100,A$2:A$100,0)),ROW(A$2:A$100)-ROW(A$2)+1),IF(B$2:B$100>B2,1)))+1+SUM(IF(FREQUENCY(IF(A$1:A1<>"",MATCH(A$1:A1,A$1:A1,0)),ROW(A$1:A1)-ROW(A$1)+1),IF(A$1:A1<>A2,IF(B$1:B1=B2,1)))),INDEX(E$1:E1,MATCH(A2,A$1:A1,0))))
confirmed with Ctrl+Shift+Enter

M.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,920
Members
448,533
Latest member
thietbibeboiwasaco

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