我试图根据几个标准对X个人进行评分和排名。每行代表1个人,并且他们按照设定的答案(即教育水平:AS,BS,MS,PhD ......等)在几个标准列上排名。我想使用CASE函数将这些答案翻译成分数(1-5)。 (即case1 education = BS,education_score = 2)并为每个类别执行此操作。然后我会将所有分数(education_score + experience_score + ...等)加起来,并根据该分数对它们进行排名。我不确定如何为工作表上的所有人使用从1到i的循环,这样无论输入了多少人,它都涵盖了所有人。我也不确定如何正确使用CASE函数根据该标准的输入将_score变量设置为正确的值。我希望有意义!
答案 0 :(得分:0)
这只是一种做你想做的事情的方式。分数需要调整到你想要的东西。此外,还需要将范围和工作表名称调整到工作表中。
我在循环记分牌时使用Ucase,因此输入High, high, HIGH, higH
等不重要。它会在代码中转换为HIGH
,因此您始终符合条件
您可以添加更多行和列,代码将自动调整循环,只需确保最后一列为Score
,除非您更改循环。
Private Sub Score()
'***********************
' Declare variables
'***********************
Dim ws As Worksheet
Dim iPersons As Integer
Dim iScore As Integer
Dim iScoreBoard As Integer
'***********************
' Initialize variables
'***********************
Set ws = Application.ThisWorkbook.Sheets("Sheet1") '<--- Change to your sheet name
iScore = 0
'***********************
' Main
'***********************
For iPersons = 2 To ws.Cells(ws.Rows.Count, 1).End(xlUp).row
For iScoreBoard = 2 To ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column - 1
Select Case UCase(ws.Cells(iPersons, iScoreBoard).Value)
'Degrees
Case "AS"
iScore = iScore + 1
Case "BS"
iScore = iScore + 2
Case "MS"
iScore = iScore + 3
Case "PHD"
iScore = iScore + 4
'Experience
Case "LOW"
iScore = iScore + 1
Case "MEDIUM"
iScore = iScore + 2
Case "HIGH"
iScore = iScore + 3
Case "EXTREME"
'Certified
Case "N"
iScore = iScore + 1
Case "Y"
iScore = iScore + 2
End Select
ws.Cells(iPersons, ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column).Value = iScore
Next iScoreBoard
iScore = 0
Next iPersons
End Sub