+ Reply to Thread
Results 1 to 9 of 9

VBA. If date = first day of the month then return months value (e.g. November)

  1. #1
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    VBA. If date = first day of the month then return months value (e.g. November)

    Hi all
    I wonder if someone can help me out.
    I have sequential dates on row 14 (horizontally) from column M to column IV ( e.g. 01/11/2011, 02/11/2011, 03/11/2011, 04/11/2011, 05/11/2011, etc...). Now I would like to achieve a macro or formula that would populate the data on row 13 (again from column M to column IV). It should look 1 cell below and if the date happens to be the first of the month then it should populate the value of the month, if its not the first of the month then leave cell empty. Let me illustrate below:

    Before macro/formula:

    Row 13 -- -------------------------------------------------------------------------------------------------------------------------------------
    Row 14 -- 01/11/2011 -- 02/11/2011 -- 03/11/2011 -- etc… -- 01/12/2011 -- 02/12/2011 -- 03/12/2011 -- etc…

    After macro/formula:

    Row 13 -- November------------------------------------------------------December--------------------------------------------------
    Row 14 -- 01/11/2011 -- 02/11/2011 -- 03/11/2011 -- etc… -- 01/12/2011 -- 02/12/2011 -- 03/12/2011 -- etc…

    I have attached spreadsheet that includes sheets "Before" and "After"

    I would appreciate if someone can help me with this.

    Cheers
    Attached Files Attached Files
    Last edited by rain4u; 11-12-2011 at 08:53 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA. If date = first day of the month then return months value (e.g. November)

    Hello rain4u

    Copy the formula below into cell M13 and drag it across.
    =IF(DAY(M$14)=1,TEXT(M$14,"mmmm"),"")
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: VBA. If date = first day of the month then return months value (e.g. November)

    And if you like to try a macro solution perhaps this could be of interest.

    Please Login or Register  to view this content.
    Alf

  4. #4
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: VBA. If date = first day of the month then return months value (e.g. November)

    Thank you Leith. Works like a charm.
    Alf,
    I didn't get it to work but thank you anyway for trying to help. Much appreciated.

  5. #5
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: VBA. If date = first day of the month then return months value (e.g. November)

    Alf,I didn't get it to work
    Sorry, my bad.

    The line
    Please Login or Register  to view this content.
    works fine for the Scandinavian date format i.e. "yyyy-mm-dd".

    For the UK format "dd-mm-yyyy" the line should be changet to:

    Please Login or Register  to view this content.
    For the US format "mm-dd-yyyy" one could use:

    Please Login or Register  to view this content.
    Alf

  6. #6
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: VBA. If date = first day of the month then return months value (e.g. November)

    Hi Alf
    Yep, got it working. I'm in UK. Its good that you gave all three versions as if anyone else after this sort of activity can use it as well.

    Thank you.

  7. #7
    Registered User
    Join Date
    05-25-2012
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VBA. If date = first day of the month then return months value (e.g. November)

    Hello !
    I have a similar issue but cant get to solve it. I have dates in column A. I just want to move the cursor to the cell(select the cell) with the first month change. This change will be a date of the first working day of the new month. Any ideas ? Thanks
    Last edited by studentt; 06-06-2012 at 08:53 AM.

  8. #8
    Registered User
    Join Date
    05-25-2012
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VBA. If date = first day of the month then return months value (e.g. November)

    Please Login or Register  to view this content.


    This selects the first day of the month in column A. But if the first working day of the month is not the first of the month, I have no solution......... Help please
    Last edited by arlu1201; 06-06-2012 at 09:18 AM. Reason: Code tags not quote tags.

  9. #9
    Registered User
    Join Date
    05-25-2012
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VBA. If date = first day of the month then return months value (e.g. November)

    Ok ive solved it. Thanks

+ 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