+ Reply to Thread
Results 1 to 6 of 6

Modify ranking code

Hybrid View

  1. #1
    Registered User
    Join Date
    10-06-2009
    Location
    Diemen, The Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    87

    Talking Modify ranking code

    Good day friends,

    I'm using this code to select the 10 lowest values and give them a ranking from 1 to 10.

    My query;

    Is it possible to modify this code so that it will give the lowest values the opposite ranking from which it is now. (Please take a look at the example sheet).

    Thank you for any help offered,


    Robert




    Sub TST()
        
        Dim A As Integer, B As Integer
        For A = 1 To 15
            For B = 1 To 10
                If Range("B1").Cells(A, 1) = Application.WorksheetFunction.Small(Range("B1:B15"), B) Then
                    With Range("B1")
                        .Offset(A - 1, 1) = B
                    End With
                    Exit For
                End If
            Next B
        Next A
        
    End Sub
    Last edited by roberto1111; 01-31-2010 at 07:26 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Modify ranking code

    Change Small to Large?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    10-06-2009
    Location
    Diemen, The Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Modify ranking code

    I mean that the code should still select 10 of the lowest values but give the opposite ranking,

    on the example sheet the code now gives the following ranking;


    500 7
    100 1 << This should be 10
    1000
    250 3
    900
    750 10 << This should be 1
    1300
    400 6
    200 2
    900
    300 4
    700 9
    350 5
    600 8
    1100

    and so on..
    Last edited by roberto1111; 01-31-2010 at 05:09 AM.

  4. #4
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: Modify ranking code

    Try the rank function with 'order' as 0 or 1 and see the difference
    ie if your data range is E4:E13, try these

    =RANK($E4,$E$4:$E$13,1)

    =RANK($E4,$E$4:$E$13,0)

    rgds

    johnjohns

  5. #5
    Registered User
    Join Date
    10-06-2009
    Location
    Diemen, The Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Modify ranking code

    Hello John,

    I got an error message while trying the formula,

    How should I set formula exactly?


    Thanks!

  6. #6
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: Modify ranking code

    See the attachment. Also do not tag your thread as 'solved' until you get the desired solution. You may not get the help from others then

    rgds

    johnjohns
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1