+ Reply to Thread
Results 1 to 6 of 6

Excel 2007 : Need vba code to determine is year is odd or even

  1. #1
    Registered User
    Join Date
    12-24-2010
    Location
    Ohio
    MS-Off Ver
    Excel 2007
    Posts
    89

    Need vba code to determine is year is odd or even

    Hi all,

    In the attached file when a new date is entered in the userform, Sheet1 C3-C206 is populated with the weekdays except for Sundays.

    What I would appreciate if someone could add some coding to the userform code that would check if the year in C3 is even then E3 = EVEN else E3 = ODD

    Just a note on my coding. The date entered in the userform will always be on a Monday, ie, 1/10/2011, 1/9/2012, etc that is why I coded the way I did to skip Sundays.
    Since I'm relatively new at this, this is what I came up with. It took me two hours to get it working.

    Thanks in advance,

    George
    Attached Files Attached Files
    Last edited by BigGPL; 02-09-2011 at 06:30 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Re: Need vba code to determine is year is odd or even

    Try,

    =IF(YEAR(C3)/2=INT(YEAR(C3)/2),"EVEN","ODD")

    There is also an =iseven() function, you may have to use the analysis toolpack add-in for that.

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Need vba code to determine is year is odd or even

    George, perhaps:

    Please Login or Register  to view this content.
    though I'd make the point that you don't really need a userform for this - you could just use formulae (with validation in C3) or VBA wise use Application.InputBox (type 1)

  4. #4
    Registered User
    Join Date
    12-24-2010
    Location
    Ohio
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Need vba code to determine is year is odd or even

    Hey Guys,

    Thanks for the replies, really appreciated.

    DonkeyOte,

    Went with your method. I do have a question, however. When you have a few extra minutes could you please explain the following code that you used

    Please Login or Register  to view this content.
    I don't even know where to begin in deciphering the above.

    Thanks,

    George

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Need vba code to determine is year is odd or even

    You don't have to use R1C1 notation if you prefer to use A1 notation (force of habit on my part)

    Please Login or Register  to view this content.
    note use of .Formula rather than .FormulaR1C1

  6. #6
    Registered User
    Join Date
    12-24-2010
    Location
    Ohio
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Need vba code to determine is year is odd or even

    Quote Originally Posted by DonkeyOte View Post
    You don't have to use R1C1 notation if you prefer to use A1 notation (force of habit on my part)

    Please Login or Register  to view this content.
    note use of .Formula rather than .FormulaR1C1
    Simpler coding, Thanks for the help

    George

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1