Numerical Series based on another column numberical values, with duplicates.

blbat

Active Member
Joined
Mar 24, 2010
Messages
338
Office Version
  1. 2016
  2. 2013
I have a column of items that have a weighted ranking value in column "C", and I need a numerical series rank in column "A" that is based on column "C".
Column "C" is always sorted smallest to largest.

Excel Workbook
ABC
1Numerical RankITEMWeighted Rank
2Item to be ranked 15.56
3Item to be ranked 221.60
4Item to be ranked 321.95
5Item to be ranked 422.05
6Item to be ranked 522.06
7Item to be ranked 622.30
8Item to be ranked 722.30
9Item to be ranked 822.38
10Item to be ranked 922.50
11Item to be ranked 1022.50
12Item to be ranked 1122.50
13Item to be ranked 1223.54
14Item to be ranked 1323.56
15Item to be ranked 1423.75
16Item to be ranked 1523.95
17Item to be ranked 1623.95
18Item to be ranked 1724.06
19Item to be ranked 1824.06
20Item to be ranked 1924.06
21Item to be ranked 2024.25
22Item to be ranked 2124.26
23Item to be ranked 2224.35
24Item to be ranked 2324.45
25Item to be ranked 2424.70
26Item to be ranked 2525.05
27Item to be ranked 2625.11
28Item to be ranked 2725.35
29Item to be ranked 2826.20
Sheet2
#VALUE!
Excel 2007


The code I have so far will fill Column "A" without accounting for duplicates:
Code:
Private Sub cmdTestRank_Click()
Dim LR As Long
LR = Cells(Rows.Count, 3).End(xlUp).Row 'find last row used
MsgBox (LR) 'test msgbox purpose to verify last row- DELETE later.
 
With Worksheets("Sheet2")
    .Range("A2").Value = "1"
    .Range("A2").Select
End With
ActiveCell.Offset(1, 0).Resize(LR - 2, 1).FormulaR1C1 = "=R[-1]C+1"
End Sub

Any Help would be greatly appreciated.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG21Sep15
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("C2"), Range("C" & Rows.Count).End(xlUp))
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
    [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
        [COLOR="Navy"]If[/COLOR] Not .Exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
            n = n + 1
            .Add Dn.Value, n
            Dn.Offset(, -2) = n
        [COLOR="Navy"]Else[/COLOR]
            Dn.Offset(, -2) = .Item(Dn.Value)
        [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Thank you both very much for the replies.

Arul.rajesh- I tried =RANK(C2, $C$2:$C$29, 1) and it accounts for the duplicates BUT it does not increment the following cell the way I want...(i.e., Rows 7 and 8 are marked with value of "6", but row 9 is then marked with value of "8" instead of "7")


Mick- this works great, now I have to figure out WHY it works great so I learn.

I figure a google on "scripting.dictionary" is in my future!
 
Upvote 0
In "A2" put 1

and in A3 put

"=IF(C3=C2,A2,A2+1)"

and drag it down this will work if you say your data is always sorted smallest to largest.

Now for that CreateObject("scripting.dictionary")
 
Upvote 0
Try this:-
Code:
[COLOR=navy]Sub[/COLOR] MG21Sep15
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range, Dn [COLOR=navy]As[/COLOR] Range, n [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
[COLOR=navy]Set[/COLOR] Rng = Range(Range("C2"), Range("C" & Rows.Count).End(xlUp))
[COLOR=navy]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
    [COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
        [COLOR=navy]If[/COLOR] Not .Exists(Dn.Value) [COLOR=navy]Then[/COLOR]
            n = n + 1
            .Add Dn.Value, n
            Dn.Offset(, -2) = n
        [COLOR=navy]Else[/COLOR]
            Dn.Offset(, -2) = .Item(Dn.Value)
        [COLOR=navy]End[/COLOR] If
    [COLOR=navy]Next[/COLOR]
[COLOR=navy]End[/COLOR] With
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick

Nice code.

Biz
 
Upvote 0
Arul.rajesh- That is a clean bit of formula writing!! it embarasses me that I did not consider such a straightforward formula.

However, the code that Mick wrote I attached to a command button that remains on the sheet...it's easier to click it than it is to drag and drop a formula.

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,334
Members
452,907
Latest member
Roland Deschain

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