Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ranking using multiple criteria

Posted on 2011-03-13
3
Medium Priority
?
333 Views
Last Modified: 2012-05-11
I'm trying to rank five objects, call them objects a, b, c, d and e.  Each object has two "scores". Cells a1, b1, c1, d1 and e1 hold one set of scores for objects a, b, c, d and e respectively.  These scores are either an H (for 'high'), an M (for 'medium') or an L (for 'low').  Cells g1, h1, i1, j1 and k1 held the second set of scores.  These are numbers, with a higher number being a better score.  There are multiple sets of object, ie multiple rows of data.

I'll rank the objects on the first set of scores (columns a thru e).  All objects with an H get the highest rank, and among those, the objects should be ranked according to the second set of scores.  Then, all objects with an M are ranked according to their second set of scores, and finally the Ls are ranked according to their scores.  For example,

The objects are: a, b, c, d, e
The first set of scores are: M, H, M, L, H
The second set of scores are: 64, 57, 73, 62, 71

The ranking should be: e, b, c, a, d

Thanks for your help...
0
Comment
Question by:pwflexner
[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
3 Comments
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 500 total points
ID: 35122291
Here is one way to do it. Run the macro "Sample" and the data will be auto populated in cells C5:G5

Sid

Code Used

Sub Sample()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim i As Long, j As Long
    
    Application.ScreenUpdating = False
    
    Set ws1 = ActiveSheet
    Set ws2 = Sheets.Add
    
    ws1.Range("A2:E2").Copy
    ws2.Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=True
    
    ws1.Range("G1:K1").Copy
    ws2.Range("B1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=True
    
    ws1.Range("A1:E1").Copy
    ws2.Range("C1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=True
    
    ws2.Sort.SortFields.Clear
    ws2.Sort.SortFields.Add Key:=ws2.Range("A1:A5"), _
    SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ws2.Sort.SortFields.Add Key:=ws2.Range("B1:B5"), _
        SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ws2.Sort
        .SetRange ws2.Range("A1:C5")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    
    j = 10
    For i = 5 To 1 Step -1
        If UCase(ws2.Range("A" & i).Value) = "L" Then
            ws2.Range("A" & i & ":C" & i).Cut ws2.Range("A" & j & ":C" & j)
            j = j - 1
        End If
    Next i
    
    ws2.Cells.SpecialCells(xlCellTypeBlanks).Delete shift:=xlUp
    
    ws2.Range("C1:C5").Copy
    ws1.Range("C5").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=True
    
    Application.DisplayAlerts = False
    ws2.Delete
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub

Open in new window

sort-results.xlsm
0
 

Author Comment

by:pwflexner
ID: 35122410
Thanks!! This is great.
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35122414
Glad you like it :)

Sid
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

618 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