Today is the first day of learning Wangpei Feng teacher VBA courses, data processing simple
exercises 1,
1. Under E content, the F called "sir" or "ma'am,"
according to the contents of column B to display code-named "Tech" in column C - "LG", "liberal arts" - "WK", "Finance" - "CJ".
The column D, row delete names empty
raw data was as follows:
Treatment effect is as follows:
VBA code;
Sub Chuli ()
'i is defined as the integer type
Dim i of As Integer
' is defined for the cycle
For i = 26 To 2 Step -1
‘根据条件生成先生与女士
If Range("E" & i) = "男" Then
Range("F" & i) = "先生"
Else
Range("F" & i) = "女士"
End If
’根据条件生成代号
If Range("B" & i) = "理工" Then
Range("C" & i) = "LG"
ElseIf Range("B" & i) = "文科" Then
Range("C" & i) = "WK"
ElseIf Range("B" & i) = "财经" Then
Range("C" & i) = "CJ"
End If
‘删除姓名为空的行
If Range("D" & i) = "" Then
Rows(i & ":" & i).Select
Selection.Delete shift:=xlUp
End If
Next
End Sub
Code is too simple, so write it