繁体   English   中英

更改另一个单元格的值

[英]Change the value of another cell

我正在寻找Excel-Vba代码,以便根据另一个单元格的值直接在某个单元格中显示某个文本,让我详细说明一下。 表格如下:

  1. 我将在单元格A3:A13中的A列中输入成绩
  2. 该代码必须自行打印相应的注释,例如a1-很好,a2-很好
  3. 此代码必须适用于例如40个等级条目的范围

Grades  ------          Comments
a1      ------          excellent 
b2      ------          work harder
a1      ------          excellent
b1      ------          satisfactory
a2      ------          good work

以下代码将继续,直到在A列中找到尚未评分的学生为止:

Sub gradeComments()

    Dim grade As String, comment As String
    Dim i As Integer

    i = 3 ' your starting row

    Do While i > 0

      grade = Range("A" & i).Value

      If grade = "a1" Then
         comment = "Excellent"
      ElseIf grade = "a2" Then
         comment = "Good work"
      ElseIf grade = "b1" Then
         comment = "Satisfactory"
      ElseIf grade = "b2" Then
         comment = "Work harder"
      End If

      If grade = vbNullString Then
        Exit Do
      Else
        Range("B" & i) = comment
        i = i + 1
      End If
    Loop
End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM