PGSystemTester

Ranking On Conditions

Apr 4th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function RankThatSucker(theRank As Integer, DivisionRange As Range, DivisionNumber As Variant, CategoryRange As Range, CategoryType As Variant, DataRange As Range) As Double
  2. Dim WS As Worksheet, rCell As Range, Cat_Column As Integer, Div_Column As Integer, i As Long
  3. Set WS = Sheets(CategoryRange.Parent.Name)
  4. Set DataRange = Intersect(DataRange, WS.UsedRange)
  5. Cat_Column = CategoryRange.Cells(1, 1).Column
  6. Div_Column = DivisionRange.Cells(1, 1).Column
  7.  
  8. Dim uData As Range
  9.  
  10.  
  11. ReDim prime_array(Application.WorksheetFunction.CountIf(Intersect(CategoryRange, WS.UsedRange), CategoryType)) As Double
  12.  
  13. For Each rCell In DataRange.Cells
  14. If WS.Cells(rCell.Row, Div_Column).Value2 = DivisionNumber Then
  15.     If WS.Cells(rCell.Row, Cat_Column).Value2 = CategoryType Then
  16.         If IsNumeric(rCell) Then
  17.             prime_array(i) = rCell.Value2
  18.             i = i + 1
  19.            
  20.         End If
  21.     End If
  22. End If
  23.  
  24. Next rCell
  25.  
  26. RankThatSucker = Application.WorksheetFunction.Large(prime_array(), theRank)
  27.  
  28. End Function
Add Comment
Please, Sign In to add comment