[英]Change the value of another cell
我正在尋找Excel-Vba代碼,以便根據另一個單元格的值直接在某個單元格中顯示某個文本,讓我詳細說明一下。 表格如下:
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.