+ Reply to Thread
Results 1 to 20 of 20

Formatting selected dates

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Formatting selected dates

    I'd like to be able to select a date in my Word document and convert it from something like "7/31/15" to "31st July, 2015". The macro below almost does it, but doesn't allow for selecting or inputting a date, and insteads inserts today's date. I've fooled around with selectng or inputting a date but can't get it to work. Any help would be appreciated.
    Please Login or Register  to view this content.
    Last edited by jomili; 07-31-2015 at 11:14 AM. Reason: forgot to put in the macro

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Formatting selected dates

    Please Login or Register  to view this content.
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Formatting selected dates

    Daffodil,
    That's 98% there. The only issue I see is that the ordinal is not appearing as superscript.

  4. #4
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Formatting selected dates

    I'm not sure I see the issue. Perhaps you've chosen a font that doesn't do superscripts?
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Formatting selected dates

    Nope, I've tried with Courier New, TimesNewRoman, and Calibri, and get the same results each time. See the picture. Any ideas?
    Attached Images Attached Images

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Formatting selected dates

    Assuiming you can use calendar content controls in your document, try the attached. the use of such a content control will ensure the input of a valid date. Even if you can't use one, though, the code shows how the superscripting can be implemented.
    Attached Files Attached Files
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  7. #7
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Formatting selected dates

    Macropod,
    The content control seems to be specific to the document, and the area in the document, if I'm understanding your macros. But what I'm wanting is more of an "on the fly" solution. I get hundreds of Word and Excel documents sent to me, and quite often I have to change a date (not all dates) from something like "7/31/15" to "31st July, 2015". Daffodil's code works for Word, only issue is I'd like the oridinal to be in superscript, and even though that functionality works for him it's not working for me.

  8. #8
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Formatting selected dates

    I've done some testing with it and was able to occasionally produce the same issue. I believe it has to do with how much is selected.

    When selecting the date only, it reliably produces the intended result, but when selecting even a single proceeding space it sometimes omits the superscript.

  9. #9
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Formatting selected dates

    So, do you want a macro that requires you to select the dates to be reformatted, or would you prefer one that searches out the dates in the document and asks which ones you want to reformat? Also, I note that the dates you've asked for help with are in the US m/d/yyyy format. Are all the dates formatted that way?

  10. #10
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Formatting selected dates

    Daffodil,
    Maybe it also depends on what day you run the macro; I tested it again this morning and it worked flawlessly, even whan I selected a space in front. So instead of my earlier "98%", lets bump this one up to 99% since you saw some glitches.

    Macropod,
    I was thinking of simply modifying the selected date, but I could see the capability of doing it document-wide at times. Since I live in the US and work with State and Federal goverment, most of my dates are in US formats mm/dd/yyyy format, mm/dd/yy, m/d/yy or m/d/yyyy.

  11. #11
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Formatting selected dates

    Try the following macro, which will interactively reformat all dates in a selected range of text.

    Please Login or Register  to view this content.

  12. #12
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Formatting selected dates

    Macropod,
    Great start! Because the dates come to me in every conceivable combination I tested the macro by feeding it dates formatted like the following:
    03/08/15, 3/8/15, 3/8/2015, and 03/08/2015 .

    Results were: "08th Mar, 2015, 8th Mar, 2015, 8th Mar, 2015, and 08th Mar, 2015"

    So, in these cases where we have a date input as 03/08, how do we keep the "0" out of the result?
    And, how can we get "March" instead of "Mar"?

  13. #13
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Formatting selected dates

    Try changing:
    Please Login or Register  to view this content.
    to:
    Please Login or Register  to view this content.

  14. #14
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Formatting selected dates

    Hmm, that took off the "0" at the beginning, but jacked up the dates. For instance, using "03/07/14", expected result should be "7th March, 2014", actual result is "3rd July, 2014"

  15. #15
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Formatting selected dates

    Quote Originally Posted by jomili View Post
    Hmm, that took off the "0" at the beginning, but jacked up the dates. For instance, using "03/07/14", expected result should be "7th March, 2014", actual result is "3rd July, 2014"
    The result I get using "03/07/14" is "7th March, 2014"...

    You could try:
    StrTxt = CInt(Split(.Text, "/")(1)) & " " & Format(Split(.Text, "/")(0) & "/" & Split(.Text, "/")(2), "MMMM, YYYY")
    Last edited by macropod; 08-07-2015 at 05:24 AM.

  16. #16
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Formatting selected dates

    Just to make sure I hadn't imagined my last results, I tried "03/07/14" again. Still came out as 3rd July,2014.

    So I then changed
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    After the change I tested by selecting these dates:
    Please Login or Register  to view this content.
    Results:
    Please Login or Register  to view this content.
    So we're extremely close. How do we put in an exception to handle a date inputted like 3/7/14?
    Last edited by jomili; 08-07-2015 at 08:55 AM.

  17. #17
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Formatting selected dates

    Try:
    StrTxt = CInt(Split(.Text, "/")(1)) & " " & Format(Split(.Text, "/")(0) & "/0", "MMMM") & " " & Format(CDate("1/1/" & Split(.Text, "/")(2)), "YYYY")

  18. #18
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Formatting selected dates

    Wow, looks like 100%. I tried to trip it up by using a menagerie of dates, and it worked flawlessly! Thank you so much for pressing on to a solid solution!

  19. #19
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Formatting selected dates

    Depending on your regional settings, you may instead be able to use:
    StrTxt = Format(CDate(.Text), "D MMMM, YYYY")

  20. #20
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Formatting selected dates

    Yes, that works absolutely fine for me, and is much easier to understand. Thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 11
    Last Post: 05-04-2014, 08:28 PM
  2. Conditional Formatting with approaching due dates and completed dates
    By rogernation in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-13-2013, 04:12 PM
  3. Replies: 2
    Last Post: 11-26-2013, 11:04 AM
  4. Replies: 4
    Last Post: 08-29-2013, 11:23 AM
  5. [SOLVED] Conditional Formatting of: dates within 1 month and dates before today.
    By Luke Smith in forum Excel General
    Replies: 5
    Last Post: 06-18-2013, 07:29 AM
  6. Difference between selected dates. Tradeday between 7:00 and 18:00
    By marcopo86 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-11-2013, 04:33 AM
  7. Populate dates by selected month
    By cggamer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-09-2007, 01:03 PM

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