vba if语句
if判断有三种格式
Sub Test() Dim the_value the_value = ThisWorkbook.Sheets("Sheet1").Range("A1").Value End Sub
1.if...endif
With ThisWorkbook.Sheets("Sheet1") If the_value = "1" Then MsgBox (the_value) End If End With
2.if...else...endif
With ThisWorkbook.Sheets("Sheet1") If the_value = "1" Then MsgBox (the_value) Else MsgBox (the_value) End If End With
3.if...elseif...else...endif
With ThisWorkbook.Sheets("Sheet1") If the_value = "1" Then MsgBox (the_value) ElseIf the_value = "2" Then MsgBox (the_value) ElseIf the_value = "3" Then MsgBox (the_value) Else MsgBox (the_value) End If End With