+ Reply to Thread
Results 1 to 10 of 10

Convert month name to 2 digits

  1. #1
    Registered User
    Join Date
    05-15-2012
    Location
    Brisbane
    MS-Off Ver
    Excel 2010
    Posts
    34

    Convert month name to 2 digits

    Hi all

    Searched for 2 hours yesterday and came up dry.

    I need to convert January, February, etc to 01, 02 (2 digits), I can get single digits but not double.

    Can anyone assist?

    Thanks
    Sean

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Convert month name to 2 digits

    You can format the cell with Number/Custom: 00 (double zero)

  3. #3
    Registered User
    Join Date
    05-15-2012
    Location
    Brisbane
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Convert month name to 2 digits

    Hi

    Thanks but I need to amend it through a variable.

  4. #4
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Convert month name to 2 digits

    If you explain what your doing and show how you are trying to do it maybe someone else could be of some help.

  5. #5
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: Convert month name to 2 digits

    Please Login or Register  to view this content.
    Source: http://stackoverflow.com/questions/1...me-into-number
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  6. #6
    Registered User
    Join Date
    05-15-2012
    Location
    Brisbane
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Convert month name to 2 digits

    I need to convert the name of the month to a corresponding number, i.e. January will be 01, but I need the leading 0

  7. #7
    Registered User
    Join Date
    05-15-2012
    Location
    Brisbane
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Convert month name to 2 digits

    Special-K = Legend

    Thank u

  8. #8
    Registered User
    Join Date
    04-12-2013
    Location
    Sacramento, CA
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Convert month name to 2 digits

    To use the following function in your code just use something like:

    activesheet.range("A1").value = convert_month("January")

    This will return the string "01" which you can work with. Anyway, unless someone is actually typing in the month in this text-type way, you're better off using a formula like the following:

    =IF(MONTH(A1)<10,CONCATENATE(0,MONTH(A1)),MONTH(A1))

    Where "A1" is the range with an actual date in it.


    Please Login or Register  to view this content.

    Sorry if this reply is a little cluttered.

    Moderators note: code tags added for you - this time
    Last edited by FDibbins; 04-19-2013 at 01:00 AM.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Convert month name to 2 digits

    There are surely 100 ways to do this.

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  10. #10
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Convert month name to 2 digits

    @ crosservice, welcome to the forum

    when you post VBA code, please use code tags, it makes it easier to read and understand - see my notes below on how to use them
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ 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