Solved

Ranking data records using VBA

Posted on 2014-02-10
2
358 Views
Last Modified: 2014-02-10
Dear Experts:

I got two columns on the active worksheet

Column A: Overall Count of Items
Column B: The respective rank where duplicate values get the same rank and with no skipping of subsequent ranks.

There is a wonderful formula in Cell B2 that achieves this feat. Courtesy by barryhoudini from EE.
=IF(A2="";"";SUMPRODUCT((A$2:A$16>A2)/COUNTIF(A$2:A$16;A$2:A$16&""))+1)
This  formula is then simply copied down.

Now comes my problem:

This formula is to be filled into B2 of a worksheet called 'Results' and then copied down using VBA. The range can vary, there could be just 16 data records, but there also could be hundreds of data records that should be ranked.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

I have attached a sample file for your convenience.

Regards, Andreas


Count      Rank
800           1
408           2
380           3
260           4
260           4
106           5
  98           6
  98           6
  78           7
  54           8
  54           8
  48           9
  44         10
  28         11
  24         12

Ranking-data-records-using-VBA.xlsx
0
Comment
Question by:AndreasHermle
2 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
Hi,

pls try

Sub Mactro5()
LastRow = Range("A" & Cells.Rows.Count).End(xlUp).Row
Range("B2:B" & LastRow).Formula = _
    "=IF(A2=" & Chr(34) & Chr(34) & "," & Chr(34) & Chr(34) & ",SUMPRODUCT((A$2:A$" & LastRow & ">A2)/COUNTIF(A$2:A$" & LastRow & ",A$2:A$" & LastRow & "&" & Chr(34) & Chr(34) & "))+1)"
End Sub

Open in new window

Regards
0
 

Author Closing Comment

by:AndreasHermle
Comment Utility
Hi Rgonzo,

I am indeed deeply impressed by your expertise.

Works like a charm. Thank you very much for your professional and swift support. I really appreciate it.

Regards, Andreas
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now