Application.WorksheetFunction.Year

Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: Application.WorksheetFunction.Year

  1. #1
    Board Regular
    Join Date
    May 2002
    Location
    CT
    Posts
    2,915
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Application.WorksheetFunction.Year

     
    I have a UDF that needs to compute the year of a date. The date variable (Issue) is declared as a date. When I use Application.WorksheetFunction.Year(Issue) I get a value error. Any suggestions. Thanks.

    Seti

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sunny, spring-like Hull
    Posts
    3,339
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Application.WorksheetFunction.Year

    VBA has its own Year function, just use that instead-

    Code:
    Dim myYear as Integer
    
    myYear = Year(Date)

  3. #3
    Board Regular
    Join Date
    May 2002
    Location
    CT
    Posts
    2,915
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Application.WorksheetFunction.Year

    Thanks for the quick reply. That is indeed correct as well as month and day. The next problem is that I need the DATE function. This does not appear to have a VBA version and I am getting a value error (#VALUE) when I use the following code:

    If Issue >= Application.WorksheetFunction.Date(Year(Issue), Month(Birth), Day(Birth)) Then

    where Issue and Birth are both date variables.

  4. #4
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sunny, spring-like Hull
    Posts
    3,339
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Application.WorksheetFunction.Year

    Take a look at the DateSerial function, does the same thing-

    If Issue > = DateSerial(Year(Issue), Month(Birth), Day(Birth)) Then

    etc etc

  5. #5
    Board Regular
    Join Date
    May 2002
    Location
    CT
    Posts
    2,915
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Application.WorksheetFunction.Year

      
    Thanks, that seems to do it.

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com