We help IT Professionals succeed at work.
Get Started

isDate function

inzhagi
inzhagi asked
on
419 Views
Last Modified: 2010-05-01
I want to validate the year function...if i want to validate the date enter by a user i will use isDate funtion but how if only year..
this is my script........


If Target.Address = "$J$28" Then
    If Sheet1.Range("J28").Value <> Empty Then
        If Right(Sheet1.Range("J28"), 4) <= 1999 Then
                    MsgBox "Tahun taksiran mesti >= 2000", , "Borang CP204"
                    Sheet1.Range("J28") = ""
                    Sheet1.Range("J28").Activate
             
       
        ElseIf Len(Sheet1.Range("J28")) = 4 Then
            Sheet1.Range("J28") = Mid((Sheet1.Range("J28")), 1, 4)
        ElseIf Len(Sheet1.Range("J28")) < 4 Then
            MsgBox "Tahun yang dimasukkan tidak sah", , "Borang CP204"
            Sheet1.Range("J28").Activate
            Sheet1.Range("J28") = ""
               
        ElseIf Len(Sheet1.Range("J28")) = 4 Then
            If Not isDate(Sheet1.Range("J28")) Then
                MsgBox "Tahun yang dimasukkan tidak sah", , "Borang CP204"
                Sheet1.Range("J28").Activate
                Sheet1.Range("J28") = ""
    Else
        TarikhBayar = Sheet1.Range("J28")
            If Sheet1.Range("L32") <> "" Then
                If IsDate(Sheet1.Range("L32")) Then
                    TempohHingga = Sheet1.Range("L32")
                    If TarikhBayar > TempohHingga Then
                        MsgBox "Tempoh awal perakaunan mesti < dari tempoh akhir perakaunan", , "Borang CP204"
                        Sheet1.Range("J28") = ""
                        Sheet1.Range("J28").Activate
                    End If
                End If
            End If

               
        End If
    End If
End If
End If


can u modify this code?i need a code that can validate the year by not using the isDate....is there any function to check the year...
Comment
Watch Question
This problem has been solved!
Unlock 2 Answers and 7 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE