+ Reply to Thread
Results 1 to 4 of 4

Opening CSV File & It Removes Spaces From Date Columns?

  1. #1
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Opening CSV File & It Removes Spaces From Date Columns?

    Hello
    When I open a downloaded csv file with vba it shows the the date & time in the correct format for the month that appears at the top of the column. The column comes formatted in dd/mm/yyyy hh:mm. Scroll down to where the next month starts & the date & time appear as text on the left of the column, but still displaying almost the same. After looking at it I noticed that there are 2 spaces between the date & time for the top rows & where it changes month, one of the spaces is removed & it displays as text. Enter another blank space & it then displays correctly as a date. Open the csv file manually & this doesn't happen.
    I've tried saving as xlsx & it's still the same scenario.
    The vba to open it is Workbooks.Open Filename:= Path & Filename & I've tried Workbooks.Open(Path & Filename)
    Both with the same result. As soon as it's open, it's ok for the latest month, after that & at the change of date between months, it displays as text
    Any ideas why?

    Thanks
    Last edited by Philb1; 10-10-2013 at 04:21 AM.

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

    Re: Opening CSV File & It Removes Spaces From Date Columns?

    I think you need to open the file in Notepad then you will be able to look at the original data directly - can you deduce anything from that? (i.e. dates in a different format from what you are expecting)

    Hope this helps.

    Pete

  3. #3
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Opening CSV File & It Removes Spaces From Date Columns?

    Hi Pete
    I can open it & see it perfectly alright when I open it manually with a double click. It's when I open it with VBA the problem shows. It's a file of transactions I'm importing into a journal workbook. I have found a way round it, but it's a rigmarole. Open it with vba, then do a replace what " ", Replacement " " on the affected columns. Then I have to select all the cells one by one to simulate pressing enter & getting it to display as a date
    Last edited by Philb1; 10-09-2013 at 06:10 AM. Reason: Website removed the extra space in replacement

  4. #4
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Opening CSV File & It Removes Spaces From Date Columns?

    For anyone that's interested. The answer is to (via the ribbon data tab) import the csv file into excel, set delimiter as comma & date as DMY. Then it all appears with the date set properly and as a date, not text. After figuring that out, I recorded it as a macro & then tidied the code. Doing it this way opens any csv file properly.

+ 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] Hide columns at opening of file with macro
    By FlyFisherman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-22-2013, 02:35 PM
  2. UserForm - vba errors only when opening Excel file from Spaces site
    By dannyboy1974 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2013, 01:36 PM
  3. Replies: 0
    Last Post: 10-22-2012, 06:52 PM
  4. [SOLVED] Save as .csv file removes trailing 00
    By Geir Holme in forum Excel General
    Replies: 2
    Last Post: 09-12-2005, 06:05 AM
  5. Renaming File Removes Worksheets
    By Dustin D. Cook in forum Excel General
    Replies: 2
    Last Post: 04-07-2005, 06:06 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