View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
JMay JMay is offline
external usenet poster
 
Posts: 422
Default Clarification please...

Arvi:
Thanks for response. So there are two forms of "If";

1) The Single-line form - If True then Statement <<<< Not requiring
"End If"
2) The Block form - If True then Statement, ElseIf, Else, EndIf
<<<<Requiring "EndIf"

The second forms appears plentifully in Code compared to the first. Is
there a "rule"
which directs you to apply #1 versus #2?

TIA,

"Arvi Laanemets" wrote in message
...
Hi

If has 2 possible syntaxes. From MS Visual Basic Help:
If condition Then [statements] [Else elsestatements]

Or, you can use the block form syntax:

If condition Then
[statements]

[ElseIf condition-n Then
[elseifstatements] ...

[Else
[elsestatements]]

End If

In your example the single-line form is used. You probably got confused
because the command line was splitted.
If ThisWorkbook.Sheets("Sheet1").Range("A1").Value < True _
Then Cancel = True

is same as
If ThisWorkbook.Sheets("Sheet1").Range("A1").Value < True Then Cancel =
True


--
Arvi Laanemets
(Don't use my reply address - it's spam-trap)



"JMay" wrote in message
news:nEric.16454$VQ3.11320@lakeread06...
I thought there was this rule where if you use the "If" keyword
somewhere afterwards one had to follow-up with the "End If" phrase.
Obviously not. Maybe the rule only applies in a Standard module
and not a class module like below. Can someone clarify?
Thanks in advance..


Private Sub Workbook_BeforeClose(Cancel As Boolean)
If ThisWorkbook.Sheets("Sheet1").Range("A1").Value < True _
Then Cancel = True
End Sub