[英]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.