if判断 代码语言:javascript 代码运行次数:0 运行 AI代码解释 单条件判断 Sub 判断1() If Range("A1").value > 0 Then Range("B1") = "正数" Else Range("B1") = "负数" End IF End Sub 多条件判断 Sub 判断1() If Range("A1").value > 0 Then Range("B1") = "正数" ElseIf Range("A1...
Value If B3 > 10 Then MsgBox ("大于10") '弹出字符串时,必须为双引号 ElseIf B3 < 10 Then MsgBox ("小于10") Else MsgBox ("aaaa") End If MsgBox (B3) End Sub 9.选择判断结构 Select Case 语句 Sub select_test() B3 = Range("B3").Value Select Case B3 Case 1 To 10 msg = "1到...
If...Then...Else Implements Input # Kill Let Line Input # Load Lock、Unlock LSet Mid MkDir 名稱 On Error On...GoSub、On...GoTo 開啟 Option Base Option Compare Option Explicit Option Private Print # Private Property Get Property Let ...
Dim Bonus As Single If Performance = 1 Then '如果 Performance等于1,奖金等于薪水的0.1倍 Bonus = Salary * 0.1 '如果 Performance等于2,奖金等于薪水的0.09倍 ElseIf Performance = 2 Then Bonus = Salary * 0.09 Else '如果 Performance不等于1也不等于2,则奖金等于0 Bonus = 0 End If End Function 2...
To run only one statement when a condition isTrue, use the single-line syntax of theIf...Then...Elsestatement. The following example shows the single-line syntax, omitting theElsekeyword. VB SubFixDate() myDate =#2/13/95#IfmyDate < NowThenmyDate = NowEndSub ...
当然还可以有很多elseif子句来嵌套。 除了if else 语句还有一种Select Case语句,这里就不做相信介绍了 5.程序调试 在程序设计领域中,经常会出现各种bug,所以在很多时候,我们为了保证代码的可维护性,我们需要使用debug的方式来更好的捕捉代码的错误。 VBA的错误分为3类:编译错误,运行时的错误,逻辑错误 编译错误,通...
If...Then...Else Implements Input # Kill Let Line Input # Load Lock、Unlock LSet Mid MkDir 名稱 On Error On...GoSub、On...GoTo 開啟 Option Base Option Compare Option Explicit Option Private Print # Private Property Get Property Let ...
If TypeName(Selection) <>"Range" Then MsgBox "请选择单元格区域!" Exit Sub Else Set rng = Selection '操作代码 End If End Sub 判断是否选择图表 下面的代码展示了如何确保是对图表执行操作: Sub DoWithChart() Dim cht As Chart '是否选择了图表 ...
Sub 选择蓝色字体的单元格() Dim rng As Range, rg As Range For Each rng In ActiveSheet.UsedRange If rng.Font.ColorIndex = 5 Then If rg Is Nothing Then Set rg = rng Else Set rg = Application.Union(rg, rng) End If End If Next rg.Select End Sub 1. 2. 3. 4. 5. 6. 7. 8. ...
If...Then...Else Implements Input # Kill Let Line Input # 加载 Lock、Unlock LSet Mid MkDir 名称 On Error On...GoSub、On...GoTo 打开 Option Base 选项比较 Option Explicit Option Private Print # 私人 Property Get Property Let Property Set ...