+ Reply to Thread
Results 1 to 6 of 6

Macro not working properly for conversion of date format

  1. #1
    Registered User
    Join Date
    03-07-2013
    Location
    zurich
    MS-Off Ver
    Excel 2010
    Posts
    99

    Macro not working properly for conversion of date format

    Hi,

    In the attached sheet, one macro is developed which is not working properly. Can anyone help me.

    My req is to convert date from dd-mon-yyyy to yyyy/mm/dd format. (23-jan-2010--> 2010/01/23)

    If incomplete date is there, then hyphen should place the gap i.e.

    For date like APR-2014------> Output should be 2014/04/--
    For date like 1998 -----> Output should be 1998/--/--

    The below macro works only for row number 11, 15 and 16. can anyone have a look on it


    Please Login or Register  to view this content.
    Attached Files Attached Files

  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: Macro not working properly for conversion of date format

    Well, all of the cells are in General Format even if the way the data isn't. First, you should loop through with .Value = .Value, which will coerce the values into the formats they were entered as.

    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
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Macro not working properly for conversion of date format

    Also, you can run a quick check on the data types with

    Please Login or Register  to view this content.
    which prints out in the immediate window:

    General
    mmm-yy
    d-mmm-yy
    d-mmm-yy
    d-mmm-yy
    d-mmm-yy
    d-mmm-yy
    d-mmm-yy
    d-mmm-yy
    dd-mmm-yyyy
    d-mmm-yy
    d-mmm-yy
    d-mmm-yy
    dd-mmm-yyyy
    dd-mmm-yyyy
    d-mmm-yy

    There appears to be some variation to account for.

  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: Macro not working properly for conversion of date format

    There, I think I got the bugs out:

    Please Login or Register  to view this content.
    Last edited by daffodil11; 04-13-2014 at 03:57 AM. Reason: Took out my J17

  5. #5
    Registered User
    Join Date
    03-07-2013
    Location
    zurich
    MS-Off Ver
    Excel 2010
    Posts
    99

    Re: Macro not working properly for conversion of date format

    Thanks Daffodil for looking into my issue.

    But the issue is still there. The macro suggested by you is not working. All date ( including partial date) converts into number format.
    Is there any alternative way..

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

    Re: Macro not working properly for conversion of date format

    It worked fine for me. Here is an attachment with the working code.
    Attached Files Attached Files

+ 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. Macro isn't working properly.
    By EAgerton in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-27-2014, 01:14 AM
  2. Macro Not Working Properly
    By fasrose in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-17-2013, 04:49 PM
  3. Date Sort in Pivot Table - Not working properly
    By claudiocustodio in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 07-12-2013, 04:30 PM
  4. Replies: 1
    Last Post: 06-15-2012, 02:03 PM
  5. [SOLVED] Macro Not Working Properly
    By PA in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-07-2006, 11:40 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