Reputation: 162
I've been tasked to correct someones code in VBA. I've never VBA programmed before so this is very basic.
Am I correct in assuming that after the first Then it checks if the next condition is true and thats where it executes the last line?
If data.Cells(i, 3 + 4).Value <> "" Then
If data.Cells(i, 2 + y).Value <> "" Then
tilqa = data.Cells(i, 2 + y)
End If
Upvotes: 1
Views: 114
Reputation: 43585
Whenever you have a question about the functioning of a code, try to write a small example, like the one below, with MsgBox()
, showing exactly what is happening. The 1=1
and 2=2
is always evaluated to True
:
Sub TestMe()
If 1 = 1 Then
If 2 = 2 Then
MsgBox "First check here!"
Else
MsgBox "This is not checked!"
End If
MsgBox "Then check here!"
End If
End Sub
Amd this is how the If-Else-End
If may function without Else
:
Sub TestMe()
If 1 = 1 Then
If 2 = 2 Then
MsgBox "First check here!"
End If
MsgBox "Then check here!"
End If
End Sub
Upvotes: 1