Excel成绩表

时间:2018-10-18 12:12:58

标签: excel comparison cell

所以,我还没有弄清楚该怎么做。

基本上,我想要这样的东西:

P1    P2    P3                TOTAL SCORE
--    --    --                P1   P2   P3
21    /     13                 1    2    0
/     17    10
6      7    /

因此,三列必须相互比较(“ /”表示玩家没有玩过该游戏,但不必打印该游戏),三列中最大的为+1 “总分”标签中的值。

加上,有没有比将一个单元格与另一个单元格进行比较容易的方法了?我的意思是,是否可以拖动并标记所有三列中的所有单元格,并确保它们仅比较同一行中三列中的单元格?

2 个答案:

答案 0 :(得分:1)

让我们假设数据显示为Sheet1中的图片(不要更改结构):

enter image description here

  1. 打开Excel
  2. 按ALT和F11打开Visual Editor
  3. 通过>插入(在上部工具栏中)-模块(第三个选项)添加模块
  4. 粘贴以下代码并执行Sub Evaluation()(当光标位于Sub Evaluation中时按F5键)
  5. 要存储lastrow以从下一条记录继续,我使用sheet2范围A1

尝试:

Option Explicit

Public Sub Process_Data(ByVal I_Value As Long)

Dim LastRow As Long
Dim i As Long
Dim CA As Integer
Dim CB As Integer
Dim CC As Integer

With Sheet1

    LastRow = .Range("A" & Rows.Count).End(xlUp).Row

    For i = I_Value To LastRow '<= Lets say that the first score is at sheet1 column A row 3.LastRow represent the row of the last data in column A
        CA = 0
        CB = 0 '<= Every time that i change value we zero our variables to get the new value
        CC = 0
        If .Range("A" & i).Value = "/" Then '<= Check if there is a number or "/".if there is "/" we zero variable
            CA = 0
        Else
            CA = .Range("A" & i).Value
        End If
        If .Range("B" & i).Value = "/" Then
            CB = 0
        Else
            CB = .Range("B" & i).Value
        End If
        If .Range("C" & i).Value = "/" Then
            CC = 0
        Else
            CC = .Range("C" & i).Value
        End If

        If CA > CB And CA > CC Then ' <= Check which number is bigger
            .Range("E3").Value = .Range("E3").Value + 1 '<= At one point to each category
        ElseIf CB > CA And CB > CC Then
            .Range("F3").Value = .Range("F3").Value + 1
        ElseIf CC > CA And CC > CB Then
            .Range("G3").Value = .Range("G3").Value + 1
        End If
    Next i
End With

End Sub

Sub Evaluation()

Dim Value As Long
Dim LastRow As Long

LastRow = Sheet1.Range("A" & Rows.Count).End(xlUp).Row

If (LastRow = 2) Or (LastRow = Sheet2.Range("A1").Value) Then '<= Check if the table has new data
    Exit Sub
Else
    If Sheet2.Range("A1").Value = "" Then '<=Check which value will adopt be i
        Value = 3
    Else
        Value = Sheet2.Range("A1").Value + 1
    End If
End If

Call Process_Data(I_Value:=Value)

Sheet2.Range("A1").Value = Sheet1.Range("A" & Rows.Count).End(xlUp).Row '<= Record the lastrow processed out

End Sub

答案 1 :(得分:0)

使用大功能在左侧查找单个游戏的最高号码。然后,使用右侧的IF语句检查LARGE函数的值是否与玩家的游戏分数匹配。如果确实匹配(TRUE),则分配值为1。如果不匹配(FALSE),则分配值为0。然后对通过IF函数分配的每个玩家的修饰符求和。

如果在各个游戏得分中可能有平局,那么您还需要嵌套另一个IF函数来处理这种可能性。