if判断
约 326 字大约 1 分钟
2024-07-07
range
注意
会在当前工作表执行
Sub 指定区域()
Dim i As Integer
For i = 1
Range("a" & i) = i
Next
End Sub
Sub 另外的写法()
Dim ge As Range
Dim i As Integer
For Each ge In Range("a1:a10")
i = i + 1
ge = i
Next
End Sub
if语句
单分支
警告
注意Then(然后)与Than(比较)
Sub 修昵称改()
Dim i As Integer
For i = 2 To 26
If Range("e" & i) = "男" Then
Range("f" & i) = "先生"
Else
Range("f" & i) = "女生"
End If
Next
End Sub
多分支
Sub if多分支()
Dim i As Integer
For i = 2 To 12
If Range("c" & i) - 3500 <= 0 Then
Range("d" & i) = 0
ElseIf Range("c" & i) - 3500 > 0 And Range("c" & i) - 3500 <= 1500 Then
Range("d" & i) = (Range("c" & i) - 3500) * 0.03
ElseIf Range("c" & i) - 3500 > 1500 And Range("c" & i) - 3500 <= 4500 Then
Range("d" & i) = (Range("c" & i) - 3500) * 0.1 - 105
ElseIf Range("c" & i) - 3500 > 4500 And Range("c" & i) - 3500 <= 9000 Then
Range("d" & i) = (Range("c" & i) - 3500) * 0.2 - 555
ElseIf Range("c" & i) - 3500 > 9000 And Range("c" & i) - 3500 <= 35000 Then
Range("d" & i) = (Range("c" & i) - 3500) * 0.25 - 1005
ElseIf Range("c" & i) - 3500 > 35000 And Range("c" & i) - 3500 <= 55000 Then
Range("d" & i) = (Range("c" & i) - 3500) * 0.3 - 2755
ElseIf Range("c" & i) - 3500 > 55000 And Range("c" & i) - 3500 <= 80000 Then
Range("d" & i) = (Range("c" & i) - 3500) * 0.35 - 5505
Else
Range("d" & i) = (Range("c" & i) - 3500) * 0.45 - 13505
End If
Next
End Sub
退出for循环
Sub 退出for循环()
If xxx Then
Exit For
End If
End Sub