I am looking for Excel-Vba code to directly show a certain text in a certain cell based on the value of another cell ,let me elaborate . The table will be as follows:
Grades ------ Comments a1 ------ excellent b2 ------ work harder a1 ------ excellent b1 ------ satisfactory a2 ------ good work
The following code continues until it finds a student in column A which has not been graded:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.