+ Reply to Thread
Results 1 to 4 of 4

VBA not keeping correct time format

  1. #1
    Forum Contributor
    Join Date
    10-02-2013
    Location
    Houston, TX
    MS-Off Ver
    office 365
    Posts
    648

    VBA not keeping correct time format

    I have a macro that imports a text file and it has to format and adjust columns to be in the correct order and format for what will happen after that.
    I have done this with other files but this one wont work correctly.

    Sometimes I have the tab delimited file or they might send it as CSV and I just resave it as tab Delimited

    Step 1 - Import the text file as Tab Delimited
    step 2- The file adjusts the columns and format.

    Problem is in the CSV the date and time is in there properly you just have to reformat to see it correctly in (09/12/14 12:00AM)
    Once I import the macro & reformat the column to the proper format the date goes to (01/00/00 12:00 AM)

    I know the date is in there properly I can see it when looking at the CSV file. Once I resave the CSV as tab delimited it must lose the date somehow.

    Can this be corrected

    Or How can I change my import from Text File to CSV file and then reformat. Here is my import Code.

    Please Login or Register  to view this content.
    Please help I have racked my brain enough

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: VBA not keeping correct time format

    Please upload a sample text file and a sample .csv file, otherwise answers will probably be based on speculation as to the format of your dates.

  3. #3
    Forum Contributor
    Join Date
    10-02-2013
    Location
    Houston, TX
    MS-Off Ver
    office 365
    Posts
    648

    Re: VBA not keeping correct time format

    I have attached one of each you can see in the CSV the date is proper and then when you import the TXT file the format for the date is gone.
    I worked around by saving the CSV as .XLSX

    Then importing that file it worked I just dont know why I kept losing the format when saving the CSV as Text file.

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: VBA not keeping correct time format

    Thanks for uploading the files.

    they might send it as CSV and I just resave it as tab Delimited
    When you save the CSV file as 'tab delimited' it saves the text EXACTLY AS YOU SEE IT in the cells, even though the underlying value may contain additional information. When I opened the CSV file in Excel 2003 Column A (date and time) was formatted for minutes and seconds and fractions of a second only (mm:ss.0). When saving the file as tab delimited text, Column A became mm:ss.0 format (as expected).

    If you format Column A to include date and hours in addition to minutes and seconds in a custom format of your choice, that custom format will be reflected in the output file when you save the file as tab delimited text.

    Lewis

+ 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. [SOLVED] Adding of the 9 Hours in Time (In Text Format) with correct
    By thilag in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-10-2013, 04:50 AM
  2. Replies: 9
    Last Post: 08-09-2013, 12:07 AM
  3. Display message if the time format is not correct
    By hecgroups in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-12-2012, 01:46 AM
  4. Combining two tables together, keeping correct format
    By impala096 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-06-2010, 12:51 PM
  5. [SOLVED] Time format to number while keeping value
    By Jim in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-12-2006, 01:50 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