+ Reply to Thread
Results 1 to 4 of 4

Excel Macro to generate all the Monday of a month

  1. #1
    Registered User
    Join Date
    10-29-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003
    Posts
    14

    Excel Macro to generate all the Monday of a month

    Could you please help me with writing a macro which would generate all the monday's of a month?

    Input: Current month For example July 2012
    Output: 7/2/2012 7/9/2012 7/16/2012 7/23/2012 7/30/2012
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Excel Macro to generate all the Monday of a month

    Try this function

    Please Login or Register  to view this content.
    This is how you call it

    Please Login or Register  to view this content.
    Please take time to read the forum rules

  3. #3
    Registered User
    Join Date
    09-13-2012
    Location
    Mumbai
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Excel Macro to generate all the Monday of a month

    The above function generates Tuesdays. The first Tuesday of the wwk is never seen correctly and only from second Tuesday is seen correctly. I made a change and that could get Mondays. Still after a lot of permutations and combinations, the first Monday could not be generated.

  4. #4
    Registered User
    Join Date
    09-13-2012
    Location
    Mumbai
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Excel Macro to generate all the Monday of a month

    Also in the macro Steffen, you can input variables through Excel so that you can have year and month of your choice. It is as follows:

    Sub steffen()

    Dim mondays

    Dim cYear As Long
    Dim cMonth As Long
    cYear = Application.InputBox(cYear, Type:=1)
    cMonth = Application.InputBox(cMonth, Type:=1)

    mondays = get_all_mondays(cYear, cMonth)

    For i = 1 To UBound(mondays)
    Selection.Value = mondays(i)
    Selection.Offset(0, 1).Select

    Next i

    End Sub

+ 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