我正在寻找Excel-Vba代码,根据另一个单元格的值直接在某个单元格中显示某个文本,让我详细说明。表格如下:
Grades ------ Comments a1 ------ excellent b2 ------ work harder a1 ------ excellent b1 ------ satisfactory a2 ------ good work
答案 0 :(得分:0)
以下代码会继续,直到找到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