Solved

Ranking data records using VBA

Posted on 2014-02-10
2
410 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39847734
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
ID: 39847752
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

726 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