基于另一个单元格的内容在Excel中自动填充单元格

时间:2018-04-11 13:46:44

标签: excel

我很难掌握编码。我的Excel工作表有一个包含分数的单元格。我希望无论得分是在不同的单元格中填写评分:

  • 4或5等于优秀
  • 2或3等于高于平均值
  • 1,0或-1等于平均值​​
  • -2或-3等于低于平均值
  • -4或-5等于差

4 个答案:

答案 0 :(得分:1)

你可以写一个简单的UDF

Option Explicit

Public Function Score(ByVal rng As Range) As String
    If rng.Count > 1 Then
        Score = "Select single cell"
        Exit Function
    End If

    Select Case rng
    Case 4, 5
        Score = "Excellent"
    Case 2, 3
        Score = "Above Average"
    Case 1, 0, -1
        Score = "Average"
    Case -2, -3
        Score = "Below Average"
    Case -4, -5
        Score = "Poor"
    Case Else
        Score = "Unknown"
    End Select
End Function

在工作表中使用UDF的示例:

UDF call

开发人员标签添加到功能区>使用Alt + F11打开并添加标准模块并将代码放在:

标准模块中的代码:

Code in module

如果您将数据设置为表格并在右上角的单元格中输入公式,它将自动填充所有行中的公式:

Table filldown

答案 1 :(得分:0)

您必须使用嵌套的IF以及ORAND的组合(实际上只是用户偏好)。观察这个嵌套的IF公式:

=IF(OR(A1=-4,A1=-5),"Poor",IF(OR(A1=-2,A1=-3),"Below Average",IF(AND(A1>=-1,A1<=1),"Average",IF(OR(A1=2,A1=3),"Above Average",IF(OR(A1=4,A1=5),"Excellent")))))

将其放入B1并将其读取A1以下的值会产生以下结果(将其向下拖动会自动更改它以读取相邻的单元格)

Image1

答案 2 :(得分:0)

如果分数为 A1 ,则在另一个单元格中输入:

=CHOOSE(A1+6,"Poor","Poor","Below Average","Below Averrage","Average","Average","Average","Above Average","Above Average","Excellent","Excellent")

enter image description here

答案 3 :(得分:0)

INDEX / MATCH:

=INDEX({"Poor","Below Averrage","Average","Above Average","Excellent"},MATCH(A1,{-1E+99,-3,-1,2,4}))

enter image description here