Results 1 to 9 of 9

Ranking Code Amendment With System Reserved Numbers -vba

Threaded View

  1. #8
    Registered User
    Join Date
    09-23-2019
    Location
    Ghana
    MS-Off Ver
    2016 32 bit and 64 bit
    Posts
    92

    Re: Ranking Code Amendment With System Reserved Numbers -vba

    This is the solution to my problem from Mr.excel.com


    Sub Kelly()
    Dim d As Object
    Dim m As Long
    Dim ary
    
    Application.ScreenUpdating = False
    m = Range("D" & Rows.Count).End(xlUp).Row - 6 ' 6 because my data starts from row 7
    
    ary = Split("100 95 90") ' system reserved numbers for my rank
    ary = Application.Transpose(Application.Transpose(ary))
    
    
    Set d = CreateObject("scripting.dictionary")
        For i = 1 To UBound(ary)
            d(CLng(ary(i))) = Empty
        Next
    Call toRank(m, d, 4, 13, ary)
    
    
    ary = Split("1000 950 900") 'system reserved for my totals ranking
    ary = Application.Transpose(Application.Transpose(ary))
    
    
    Set d = CreateObject("scripting.dictionary")
        For i = 1 To UBound(ary)
            d(CLng(ary(i))) = Empty
        Next
    Call toRank(m, d, 14, 14, ary)
    Application.ScreenUpdating = True
    
    End Sub
    
    
    Sub toRank(m As Long, d As Object, a As Long, b As Long, ary As Variant)
    'https://www.mrexcel.com/forum/excel-questions/1113655-ranking-code-amendment-system-reserved-numbers-vba.html
    Dim i As Long, z As Long, n As Long
    Dim e As Object, f As Object
    Dim arz
    Dim c As Range
    
    
    For g = a To b
    
        arb = Application.Transpose(Cells(7, g).Resize(m)) ' 7 because my data started from row 7
        ReDim arz(1 To UBound(arb))
            
            For i = 1 To UBound(arb)
                arz(i) = WorksheetFunction.Large(arb, i)
                 
            Next i
        
        n = arz(UBound(arz))
        
        Set e = CreateObject("scripting.dictionary")
            For i = 1 To UBound(arz)
                e(arz(i)) = Empty
            Next
        
        Set f = CreateObject("scripting.dictionary")
            z = 1
            For i = ary(1) To n Step -1
                If d.Exists(i) And Not e.Exists(i) Then
                z = z + 1
                End If
    '            If e.Exists(i) Then f(i) = z: z = z + 1
                If e.Exists(i) Then f(i) = z & GetOrdinalSuffixForRank(z): z = z + 1
            Next
        
            For Each c In Cells(7, g).Resize(m) ' 7 for row 7
                If f.Exists(c.Value) Then c.Offset(, 12) = f(c.Value)
            Next
    
    Next
    
    End Sub
    
    
    Function GetOrdinalSuffixForRank(Rnk As Long) As String
     Dim sSuffix$
    If Rnk Mod 100 >= 11 And Rnk Mod 100 <= 20 Then
        sSuffix = "th"
    Else
        Select Case (Rnk Mod 10)
            Case 1: sSuffix = "st"
            Case 2: sSuffix = "nd"
            Case 3: sSuffix = "rd"
            Case Else: sSuffix = "th"
        End Select
    End If
         GetOrdinalSuffixForRank = sSuffix
    End Function
    Credit:
    Akuini
    Last edited by Kelly mort; 11-02-2019 at 05:06 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Developing a code that selects a correlation based on a ranking system of data inputs?
    By dylantulsa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-07-2019, 02:51 PM
  2. [SOLVED] Overwrite write reserved file with updated copy (same name; also write reserved)
    By Henk Stander in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-13-2014, 08:38 AM
  3. Sports Ranking System
    By moneymanminn1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-01-2013, 02:03 PM
  4. [SOLVED] Slight amendment needed to a ranking table.
    By gunnerterry in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-08-2013, 12:50 PM
  5. Need an amendment in a macro which records system time.
    By Raju Radhakrishnan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-19-2013, 12:02 AM
  6. [SOLVED] Ranking System
    By maddog9486 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-16-2011, 08:12 AM
  7. Automated ranking system
    By liero116 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-22-2010, 06:37 PM

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