Consulting

Results 1 to 4 of 4

Thread: Array for months of the calendar

  1. #1

    Array for months of the calendar

    I am very new to Vba. I am sure this is simple but can some please show me how to create an Array for the months of the year. It must be in a loop and populate the array with the months. I have tryed but what I am trying is not even close.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,264
    Location
    [vba]

    Redim VecDates(1 To 12)
    For i = 1 To 12

    vecDates(i) = DateSerial(Year(Date),i, 1)
    Next i
    [/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 Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    991
    Location
    To expand on Bob's answer, to get the months proper name:
    [VBA]vecDates(i) = Format(DateSerial(Year(Date), i, 1), "MMMM")[/VBA]

    David


  4. #4
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,938
    Location
    Quote Originally Posted by Tinbendr
    To expand on Bob's answer, to get the months proper name:
    [VBA]vecDates(i) = Format(DateSerial(Year(Date), i, 1), "MMMM")[/VBA]
    Actually it's easier than that, no need for calling two functions...
    [vba]vecDates(i) = MonthName(i, False)[/vba]

Posting Permissions

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