+ Reply to Thread
Results 1 to 10 of 10

Date Format Issue

  1. #1
    Forum Contributor
    Join Date
    09-21-2014
    Location
    Midwest USA
    MS-Off Ver
    2010
    Posts
    349

    Date Format Issue

    In the attached workbook the cells in A1 and B1 on Sheet1 have the same date format. Cell A1 I entered manually and Cell B1 is from an import using VBA from a .csv file. I want Cell B1 to look like A1 and if I click in B1 and hit enter it does. I can probably code in an Edit/Enter routine into my vba, but that seems sloppy and I was wondering if there is a better way to accomplish the desired result.

    Any suggestions? Bonus credit if you can tell me why the import is behaving that way when the format is the same.  Thanks for reading and any suggestions.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Date Format Issue

    A1 is a serial date, and B1 is a Text date. Your CSV file dates import as text entries. Even though they "look" like dates, Excel doesn't recognize them as serial dates.

    One method to convert your B1 Text-date to a serial date is to select it and press enter. Another is to select the column of dates and use either Text-to-Columns or the Replace function.

    How are you importing the CSV file?
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Date Format Issue

    Hi aquixano,

    If you imported data is text then you can use =DateValue() to convert it to real dates. Then format that column to show them as you desire.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Contributor
    Join Date
    09-21-2014
    Location
    Midwest USA
    MS-Off Ver
    2010
    Posts
    349

    Re: Date Format Issue

    I populate a userform with info from the .csv in case I want to edit anything before posting to my workbook using this code (the date code is between the two asterisk lines)

    Please Login or Register  to view this content.
    I use the following line of code to post to the final worksheet I use to log the info.

    Please Login or Register  to view this content.
    Let me know if you have other questions - thanks for the help.

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

    Arrow Re: Date Format Issue

    Quote Originally Posted by aquixano View Post
    Cell A1 I entered manually and Cell B1 is from an import using VBA from a .csv file.
    So it's just a bad import so rather than fixing the data after the import
    the better is to just well import them as Excel can handle this with a correct import setup !

    Or to fix after you can use the Text To Columns feature from the Data menu, easy to use with an assistant
    like the Import Wizard, just needs the appropriate answers in particular for the cell / column format.
    Last edited by Marc L; 04-13-2020 at 08:21 PM. Reason: typo …

  6. #6
    Forum Contributor
    Join Date
    09-21-2014
    Location
    Midwest USA
    MS-Off Ver
    2010
    Posts
    349

    Re: Date Format Issue

    Thanks AlphaFrog & MarvinP
    I added the Datevalue to the line: .Range("K" & CloseRW & "").FormulaR1C1 = Datevalue(PendingForm.tbDATE) and it solved the problem.

    I should have realized it was text based on the justification was using – guess I never realized that simply clicking in the cell and hitting enter would change the contents type (even though nothing was actually changed.

    Thanks to both of you for the help!

  7. #7
    Forum Contributor
    Join Date
    09-21-2014
    Location
    Midwest USA
    MS-Off Ver
    2010
    Posts
    349

    Re: Date Format Issue

    Thanks for the suggestion Mark L!

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

    Re: Date Format Issue


    Both ways can be used under VBA …

  9. #9
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Date Format Issue

    You're welcome. Thanks for the feedback.

    The red bit seems superfluous.

    Please Login or Register  to view this content.
    ...and there was talk of bonus points.

  10. #10
    Forum Contributor
    Join Date
    09-21-2014
    Location
    Midwest USA
    MS-Off Ver
    2010
    Posts
    349

    Re: Date Format Issue

    AlphaFrog - you definitely deserve bonus points for all the help you’ve given me today & in the past. I’ll double check the red highlighted code. Seems like I have an old memory that I couldn’t make a concatenated reference work in a piece of code without it and have just continued to do it. But I may have accidentally solved a different problem with it too. That or I’m just “mis-remembering.” Thanks for the suggestion.

+ 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] Date Format Issue
    By tom_19 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-30-2017, 04:13 PM
  2. Replies: 4
    Last Post: 04-29-2015, 08:36 AM
  3. date format issue n.2 pls help, thank you
    By cat3appr in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-26-2014, 12:52 PM
  4. Date Format, CSV issue
    By Chris Acheson in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-10-2014, 10:52 AM
  5. [SOLVED] Issue with date format when comparing two date values (I'm in Australia)
    By aaron.irvine in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2013, 01:13 AM
  6. Date Format issue
    By PRodgers in forum Excel General
    Replies: 11
    Last Post: 08-14-2009, 10:33 AM
  7. Date format issue
    By DanielHurtubise in forum Excel General
    Replies: 2
    Last Post: 09-21-2005, 02:05 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