title: Avoiding Nested IFs in VBA with "And _"
body: <p>I am trying to avoid nesting IF statements but the code below gives me an error. The error only appears when I have the first line present. Without it, the other &quot;And _&quot; work perfectly. I cannot understand why!
  For background, the objective of this code is to check that the date is in the correct format (dd/mm/yyyy) and occurs after 2020.
  Any help would be really appreciated!</p>
  <p>This code doesn't work:</p>
  <pre><code>Public ValidPaymentDate As Boolean
  Public ArrInput_PaymentDate As Variant
  
  ArrInput_PaymentDate = Split(PaymentDate.Value, &quot;/&quot;) 
  
  If (UBound(ArrInput_PaymentDate) = 2) And _ ' ***Here is the issue!!!***
      ArrInput_PaymentDate(0) &gt; 0 And ArrInput_PaymentDate(0) &lt;= 31 And _
      ArrInput_PaymentDate(1) &gt; 0 And ArrInput_PaymentDate(1) &lt;= 12 And _
      ArrInput_PaymentDate(2) &gt;= 20 And ArrInput_PaymentDate(2) &lt; 100 Then
      ValidPaymentDate = True
  End If
  </code></pre>
  <p>This code works (but I'd like to avoid nesting If statements):</p>
  <pre><code>Public ValidPaymentDate As Boolean
  Public ArrInput_PaymentDate As Variant
  
  ArrInput_PaymentDate = Split(PaymentDate.Value, &quot;/&quot;) 
  
  If (UBound(ArrInput_PaymentDate) = 2) Then
      If ArrInput_PaymentDate(0) &gt; 0 And ArrInput_PaymentDate(0) &lt;= 31 And _
      ArrInput_PaymentDate(1) &gt; 0 And ArrInput_PaymentDate(1) &lt;= 12 And _
      ArrInput_PaymentDate(2) &gt;= 20 And ArrInput_PaymentDate(2) &lt; 100 Then
      ValidPaymentDate = True
      End If
  End If
  </code></pre>