「Excel VBA」IF文に論理演算子Andを使用する方法

書式
if (条件式1) And (条件式2) Then
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Sub ifandsample()
Dim x, y As Integer
x = 34
y = 56
If (x = 34) And (y = 57) Then
Debug.Print "value is equal"
Else
Debug.Print "value is not equal"
End If
End Sub
Sub ifandsample() Dim x, y As Integer x = 34 y = 56 If (x = 34) And (y = 57) Then Debug.Print "value is equal" Else Debug.Print "value is not equal" End If End Sub
Sub ifandsample()
    Dim x, y As Integer
    x = 34
    y = 56
    
    If (x = 34) And (y = 57) Then
            Debug.Print "value is equal" 
    Else
            Debug.Print "value is not equal"
    End If
End Sub

 

Excel VBA

Posted by arkgame