+ Reply to Thread
Results 1 to 6 of 6

Formatting a column to display the date and time instead of general text using VBA

  1. #1
    Registered User
    Join Date
    10-19-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Formatting a column to display the date and time instead of general text using VBA

    Hi All,

    I am struggling with the formatting of two columns in worksheet. I am running the workbook as shared so I can track any changes through the history. I have multiple worksheets that I want to track, I have managed (with help) to copy the history for each worksheet out and into e.g. a new History-for sheet 1 and History-for sheet 2 etc allowing me to focus on the history for each individual worksheet. The history is copying over into the specific sheets fine apart from the date and time stamp, they both seem to converted to general text.

    Can anyone tell me why this happening and what code I could use to convert column 2 of History-sheet 1 to time format and column 3 to date format.
    I am using excel 2007

    Thanks in advance

    Novice coder

  2. #2
    Forum Contributor
    Join Date
    09-27-2012
    Location
    London, England
    MS-Off Ver
    2003, 2010
    Posts
    344

    Re: Formatting a column to display the date and time instead of general text using VBA

    Hi - Did you try changing the format of the columns (under format cells) to date and time respectively?
    If solved kindly remember to mark Thread as solved.
    Click the small star icon at the bottom left of my post if this was useful.

  3. #3
    Registered User
    Join Date
    10-19-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Formatting a column to display the date and time instead of general text using VBA

    Hi,

    Yes I have tried this and it works but I would like to do it under VBA if possible.

    Thanks

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: Formatting a column to display the date and time instead of general text using VBA

    Why don't you turn the macro recorder on, then change the formats manually, then stop recording and see what code you have generated. You should then be able to copy those few lines into your existing macros.

    Hope this helps.

    Pete

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Formatting a column to display the date and time instead of general text using VBA

    Try these codes

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-19-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Formatting a column to display the date and time instead of general text using VBA

    Thanks for help, I have used the code and placed it in with the rest of my code and it works fine, although I have changed "[$-409]h:mm AM/PM;@" to hh:mm:ss. Thanks again

+ 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