Consulting

Results 1 to 4 of 4

Thread: Days in Month

  1. #1
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location

    Days in Month

    I'm looking to design a data entry form to allow a user to enter financial data. The user gets to select the required Month and Year, and I would like the form to then display the required number of days per month running in sequential order down the form.

    I could set up a list of days per month for all months of the year to which the form could refer to, but this would not take into effect a "leap" year. Does Excel know if a year is a leap year or do I have to tell it so?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You don't say where they go, so I assumed a listbox.

    I am also assuming you have a combobox with month names in and another with your selectable years in.

    [vba][

    Dim i As Long
    Dim mpDate As Date

    With Me

    .ListBox1.Clear
    For i = 1 To 31

    mpDate = DateValue(i & "-" & cmbMonth.Value & "-" & .cmbYear.Value)
    .ListBox1.AddItem Format(mpDate, "dd mmm yyyy")
    If Month(mpDate) <> Month(mpDate + 1) Then Exit For
    Next i
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jun 2007
    Posts
    69
    Location
    Aussiebear,

    If you have the Analysis Pack installed, try using EOMONTH(start_date,months), which gives the EOM date that is 'months' before or after the start date.

    Or you can do hand-to-hand combat with the code and get the end date by calculating the first of the following month and subtracting 1.

    Cheers!

    PS Now, that I see El Xid's solution, I like it much more. ;-)
    Ron McKenzie
    Windermere, FL
    (living in the huge shadow of a tiny rodent)

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    Thankyou XLD & Ron
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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