+ Reply to Thread
Results 1 to 25 of 25

Changing date as string to date format

  1. #1
    Registered User
    Join Date
    06-28-2012
    Location
    India
    MS-Off Ver
    Excel 2013 and Excel 365
    Posts
    76

    Changing date as string to date format

    HI

    I am having problem in converting Date column as string to date format, when i am using date format "dd/mm/yy it is converting first two digit of strings as "mm" and next two as "dd" instead of "dd" and "mm" respectively

    PHP Code: 
     Sub IdbiStatement () 
     
    Range("D1:E500").Select
        With Selection
        
    .NumberFormat "MM/DD/yyyy"
        
    .Value = .Value


            
        End With
    End Sub 
    Attached Files Attached Files

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Changing date as string to date format

    That's because your code does that...
    Please Login or Register  to view this content.
    change it to...
    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    06-28-2012
    Location
    India
    MS-Off Ver
    Excel 2013 and Excel 365
    Posts
    76

    Re: Changing date as string to date format

    I have tried that one first but it is not helping, mean actual date is "02 Jun 2020" but excel is reading it as "06 feb 2020" if i convert it through VBA.
    Without vba, in cell D2 if i use F2 key and press enter than it is reading correct date

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Changing date as string to date format


    Hi,

    without any code with an Exel basics : the convert feature (maybe in Data menu, known also as Text To Columns)
    so just well anwsering to its Assistant …

    If really really a VBA procedure is needed it requires a single codeline just using the TextToColumns VBA method …

  5. #5
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Changing date as string to date format

    Look at this...
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    06-28-2012
    Location
    India
    MS-Off Ver
    Excel 2013 and Excel 365
    Posts
    76

    Re: Changing date as string to date format

    HI Marc L

    thanks for reply
    I just need a vba code to correct the date as "02 Jun 2020", excel is reading it as "06 feb 2020" after converting from string to date in each formats i.e dd/mm/yy or mm/dd/yy

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Changing date as string to date format


    Directly use the Excel feature on the source column to convert bad text dates to Excel dates …

  8. #8
    Registered User
    Join Date
    06-28-2012
    Location
    India
    MS-Off Ver
    Excel 2013 and Excel 365
    Posts
    76

    Re: Changing date as string to date format

    it is still showing data as a text, excel is not grouping the cell values as date

  9. #9
    Registered User
    Join Date
    06-28-2012
    Location
    India
    MS-Off Ver
    Excel 2013 and Excel 365
    Posts
    76

    Re: Changing date as string to date format

    i have to download 50+ file daily and combine them in their master sheets, so i can't do this manually for each sheet, so i have created a code to do all other formatting and adding them to master sheets but but stuck with date correction.

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: Changing date as string to date format


    How do you load data to Excel ? As maybe it's just a bad import …

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Changing date as string to date format


    The Excel feature well works on my side with your attachment …

  12. #12
    Registered User
    Join Date
    06-28-2012
    Location
    India
    MS-Off Ver
    Excel 2013 and Excel 365
    Posts
    76

    Re: Changing date as string to date format

    this is the "example file" i am directly downloading from banks website.

  13. #13
    Registered User
    Join Date
    06-28-2012
    Location
    India
    MS-Off Ver
    Excel 2013 and Excel 365
    Posts
    76

    Re: Changing date as string to date format

    and after using code it is covering first two digits into "mm" instead of "dd"

  14. #14
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Changing date as string to date format

    this is the "example file" i am directly downloading from banks website.
    Where.....

  15. #15
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Changing date as string to date format


    Kumar,

    what are your Windows Regional Settings for dates : US, UK or ?

  16. #16
    Registered User
    Join Date
    06-28-2012
    Location
    India
    MS-Off Ver
    Excel 2013 and Excel 365
    Posts
    76

    Re: Changing date as string to date format

    steps

    1. downloading file in download folder in c drive
    2. opening file
    3. copy code to downloaded file
    4. running

    vba code
    PHP Code: 

    Sub IdbiStatement 
    () 

     
    Range("D1:E500").Select
        With Selection
        
    .NumberFormat "dd/mm/yyyy"
        
    .Value = .Value
          
        End With
    End Sub 
    5. getting result in cell d2= 06/02/2020


    i am using uk date format

    Is there a way to interchange date value and month value
    Last edited by Baldev Kumar; 06-06-2020 at 01:33 PM.

  17. #17
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Changing date as string to date format

    Have you just ignored Post 5

  18. #18
    Registered User
    Join Date
    06-28-2012
    Location
    India
    MS-Off Ver
    Excel 2013 and Excel 365
    Posts
    76

    Re: Changing date as string to date format

    i have tried that but in that excel is reading date as text.

  19. #19
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Re: Changing date as string to date format


    Yes, just warming a couple of neurons & well using the Excel feature as I yet wrote …
    The next demonstration was started by a kid - I gave him as a training - using the Macro Recorder
    and just operating manually you know what : he well succeed !

    According to your attachment as a very VBA beginner starter :

    PHP Code: 
    Sub Demo4Noob1()
        
    With Range("E2:E" & [C1].CurrentRegion.Rows.Count)
            .
    Formula "=LEFT(D2,10)"
            
    .Formula = .Value
            
    .TextToColumns  .Cells(1), xlDelimitedFieldInfo:=[{14}]
        
    End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  20. #20
    Registered User
    Join Date
    06-28-2012
    Location
    India
    MS-Off Ver
    Excel 2013 and Excel 365
    Posts
    76

    Re: Changing date as string to date format

    Thanks for help,

    it working fine with single sheet but when combining with whole macro,

    it is taking long time in formatting and copying data to master sheet,

    but still this is serving my purpose.

    i will come back if found some better solution.

  21. #21
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Changing date as string to date format


    Ask the bank to be clever with at least correct Excel dates (so not as text !) in its Excel workbooks !

  22. #22
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Changing date as string to date format

    Excel is smart enough these days.

    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    06-28-2012
    Location
    India
    MS-Off Ver
    Excel 2013 and Excel 365
    Posts
    76

    Re: Changing date as string to date format

    Quote Originally Posted by Vraag en antwoord View Post
    Excel is smart enough these days.

    Please Login or Register  to view this content.
    i have already tried this
    all date in sheet are for June month but my excel is reading 06 i.e. June as "dd"

  24. #24
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Changing date as string to date format

    Try below code but not sure if its any faster than Marc's code …

    Please Login or Register  to view this content.
    If I was able to help, you can thank me by clicking the * Add Reputation under my user name

  25. #25
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Changing date as string to date format

    Try
    Please Login or Register  to view this content.

+ 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: 2
    Last Post: 04-14-2015, 04:20 PM
  2. Changing date format in a text string
    By rsmith10 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-19-2014, 09:46 AM
  3. [SOLVED] Changing Multiple sheet names by wk ending date for yr but need specific name/date format
    By kedeling in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-06-2013, 02:40 PM
  4. Need Formula/VBA Code to convert date in String Format to Normal Date format
    By Karthik Sen in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-18-2012, 04:54 AM
  5. Need help changing date to a sortable date format
    By slicksilver79 in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 12-15-2011, 10:44 AM
  6. Formula required for date without changing the date format
    By suryaprasad in forum Excel General
    Replies: 1
    Last Post: 01-28-2009, 08:04 AM
  7. [SOLVED] Changing date serial numbers to date format
    By rdunne in forum Excel General
    Replies: 1
    Last Post: 04-14-2005, 08:06 AM

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