DarthGremlin
New Member
- Joined
- Mar 25, 2009
- Messages
- 15
Hello again,
Rorya if you help me out on this one too I swear this will be the last question I'll have a long time.
So in theory I have the following data. Showing Team, Points, and player name from a game.
<TABLE style="WIDTH: 144pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=192 border=0 x:str><COLGROUP><COL style="WIDTH: 48pt" span=3 width=64><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; WIDTH: 48pt; BORDER-BOTTOM: #e0dfe3; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" width=64 height=17>Rockets</TD><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; WIDTH: 48pt; BORDER-BOTTOM: #e0dfe3; BACKGROUND-COLOR: transparent" align=right width=64 x:num>10</TD><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; WIDTH: 48pt; BORDER-BOTTOM: #e0dfe3; BACKGROUND-COLOR: transparent" width=64>Jordan</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>Rockets</TD><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; BACKGROUND-COLOR: transparent" align=right x:num>11</TD><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; BACKGROUND-COLOR: transparent">Smith</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>Hawks</TD><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; BACKGROUND-COLOR: transparent" align=right x:num>14</TD><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; BACKGROUND-COLOR: transparent">Smith</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>Rockets</TD><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; BACKGROUND-COLOR: transparent" align=right x:num>6</TD><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; BACKGROUND-COLOR: transparent">Jordan</TD></TR></TBODY></TABLE>
Now what I want to be able to do is retrieve the name of the player who scored the most points for a particular team, as well as the total points that they scored, as well as the number of times that they scored. (an admittedly weak analogy but it works)
So with this data what I want to have happen is when I type
=scoreboard(1,1,"Rockets",A1:A4,B1:B4,C1:C4)
I want the cell to show "Jordan"
but if I type
=scoreboard(1,2,"Rockets",A1:A4,B1:B4,C1:C4)
I want the cell to show 16
and if I type
=scoreboard(1,3,"Rockets",A1:A4,B1:B4,C1:C4)
I want the cell to show 2 since Jordan scored twice.
Further more if I typed
=scoreboard(1,2,"Hawks",A1:A4,B1:B4,C1:C4)
I want it to return 14 because Smith scored 14 points for the Hawks.
BTW If I type
=scoreboard(2,1,"Rockets",A1:A4,B1:B4,C1:C4)
It should return Smith
my attempt at coding this is as follows:
I get a Value error. As far as I can tell the two sub functions are working just fine. it'sthe first one that's killing it.
Rorya if you help me out on this one too I swear this will be the last question I'll have a long time.
So in theory I have the following data. Showing Team, Points, and player name from a game.
<TABLE style="WIDTH: 144pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=192 border=0 x:str><COLGROUP><COL style="WIDTH: 48pt" span=3 width=64><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; WIDTH: 48pt; BORDER-BOTTOM: #e0dfe3; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" width=64 height=17>Rockets</TD><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; WIDTH: 48pt; BORDER-BOTTOM: #e0dfe3; BACKGROUND-COLOR: transparent" align=right width=64 x:num>10</TD><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; WIDTH: 48pt; BORDER-BOTTOM: #e0dfe3; BACKGROUND-COLOR: transparent" width=64>Jordan</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>Rockets</TD><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; BACKGROUND-COLOR: transparent" align=right x:num>11</TD><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; BACKGROUND-COLOR: transparent">Smith</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>Hawks</TD><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; BACKGROUND-COLOR: transparent" align=right x:num>14</TD><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; BACKGROUND-COLOR: transparent">Smith</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>Rockets</TD><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; BACKGROUND-COLOR: transparent" align=right x:num>6</TD><TD style="BORDER-RIGHT: #e0dfe3; BORDER-TOP: #e0dfe3; BORDER-LEFT: #e0dfe3; BORDER-BOTTOM: #e0dfe3; BACKGROUND-COLOR: transparent">Jordan</TD></TR></TBODY></TABLE>
Now what I want to be able to do is retrieve the name of the player who scored the most points for a particular team, as well as the total points that they scored, as well as the number of times that they scored. (an admittedly weak analogy but it works)
So with this data what I want to have happen is when I type
=scoreboard(1,1,"Rockets",A1:A4,B1:B4,C1:C4)
I want the cell to show "Jordan"
but if I type
=scoreboard(1,2,"Rockets",A1:A4,B1:B4,C1:C4)
I want the cell to show 16
and if I type
=scoreboard(1,3,"Rockets",A1:A4,B1:B4,C1:C4)
I want the cell to show 2 since Jordan scored twice.
Further more if I typed
=scoreboard(1,2,"Hawks",A1:A4,B1:B4,C1:C4)
I want it to return 14 because Smith scored 14 points for the Hawks.
BTW If I type
=scoreboard(2,1,"Rockets",A1:A4,B1:B4,C1:C4)
It should return Smith
my attempt at coding this is as follows:
Code:
Function ScoreBoard(intRank As Integer, _
intReturnType As Integer, _
StrTeam As String, _
rngTeams As Range, _
rngPoints As Range, _
rngPlayer As Range) As Variant
' End of arguments
Dim varValue As Variant, _
varResults As Variant, _
varSortedResults As Variant
Dim boolCategorySet As Boolean
Dim intRow As Integer, _
intRowIndex2 As Integer, _
intTemp As Integer
boolCategorySet = False
If Not RangesOK(rngTeams, rngPoints) Then
'Return an error value
varValue = "Error in range selection"
Else
'If the ranges are not identically sized can not get this far!
For intRow = 1 To rngEvaluate.Rows.Count
If Application.CountIf(rngTeams(intRow, intCol), StrTeam) = 1 Then
If boolCategorySet Then
If Application.CountIf(varResults, rngPlayer(intRow, intCol)) = 1 Then
' This Player already has already scored
intTemp = Application.Match(rngPlayer(intRow, intCol), varResults([], 1), 0)
varResults(intTemp, 2) = Application.Sum(varResults(intTemp, 2), rngPoints(intRow, intCol))
varResults(intTemp, 3) = Application.Sum(varResults(intTemp, 3), 1)
Else
' This player hasn't scored yet and needs to be added
intRowIndex2 = intRowIndex2 + 1
varResults(rowIndex2, 1) = rngPlayer(intRow, intCol)
varResults(rowIndex2, 2) = rngPoints(intRow, intCol)
varResults(rowIndex2, 3) = 1
End If
Else
' first player scores
bolValueSet = True
intRowIndex2 = 1
varResults(rowIndex2, 1) = rngPlayer(intRow, intCol)
varResults(rowIndex2, 2) = rngPoints(intRow, intCol)
varResults(rowIndex2, 3) = 1
End If
End If
Next intRow
End If
varSortedResults = SortVariantD(varResults, 2)
ScoreBoard = varSortedResults(intRank, intReturnType)
End Function
________________________________________________________
Public Function SortVariantD(varData As Variant, valCol As Integer)
Dim Swapper As Variant
Dim i As Integer, _
j As Integer, _
k As Integer
For i = 1 To rngToSort.Rows.Count
For j = 1 To rngToSort.Rows.Count - i
If varData(j + 1, valCol) > varData(j, valCol) Then
For k = 1 To rngToSort.Columns.Count
Swapper = varData(j, k)
varData(j, k) = varData(j + 1, k)
varData(j + 1, k) = Swapper
Next k
End If
Next j
Next i
SortVariantA = varData
End Function
_______________________________________________________
Public Function RangesOK(rng1 As Range, rng2 As Range) As Boolean
Dim bolAreas As Boolean, _
bolSize As Boolean
bolAreas = (rng1.Areas.Count = 1) Or (rng2.Areas.Count = 1)
bolSize = (rng1.Rows.Count = rng2.Rows.Count) And _
(rng1.Columns.Count = rng2.Columns.Count)
RangesOK = bolAreas And bolSize
End Function
Last edited: