簡體   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