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 "And _" 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!
This code doesn't work:
Public ValidPaymentDate As Boolean
Public ArrInput_PaymentDate As Variant
ArrInput_PaymentDate = Split(PaymentDate.Value, "/")
If (UBound(ArrInput_PaymentDate) = 2) And _ ' ***Here is the issue!!!***
ArrInput_PaymentDate(0) > 0 And ArrInput_PaymentDate(0) <= 31 And _
ArrInput_PaymentDate(1) > 0 And ArrInput_PaymentDate(1) <= 12 And _
ArrInput_PaymentDate(2) >= 20 And ArrInput_PaymentDate(2) < 100 Then
ValidPaymentDate = True
End If
This code works (but I'd like to avoid nesting If statements):
Public ValidPaymentDate As Boolean
Public ArrInput_PaymentDate As Variant
ArrInput_PaymentDate = Split(PaymentDate.Value, "/")
If (UBound(ArrInput_PaymentDate) = 2) Then
If ArrInput_PaymentDate(0) > 0 And ArrInput_PaymentDate(0) <= 31 And _
ArrInput_PaymentDate(1) > 0 And ArrInput_PaymentDate(1) <= 12 And _
ArrInput_PaymentDate(2) >= 20 And ArrInput_PaymentDate(2) < 100 Then
ValidPaymentDate = True
End If
End If