+ Reply to Thread
Results 1 to 7 of 7

Date Format Issue

  1. #1
    Registered User
    Join Date
    08-12-2011
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2010
    Posts
    20

    Question Date Format Issue

    I have a spreadsheet with a column of dates but they're in 2 different formats. Some dates read as "30 Mar" (for March 30th) and are formatted as "General" type. Other dates read 3/30/2017, formatted as actual dates. I'm trying to use VBA to go down the column and make them all the same. For purposes of what I'm going, I'm trying to get them all to read like the "30 Mar" example, despite the other one seeming more logical.

    That said, I've put together the following code but cannot get the desired result to return in the spreadsheet's cell. I put in a MsgBox line of code just to make sure I'm getting the value I want, and that's working. The Message Box reads "30 Mar" as I want, but when it writes it to the spreadsheet I get the numeric date value "42824" no matter what format I assign to the cell.

    Am I doing something wrong? It would seem my code works based on the Message Box output, so I'm thinking it's something to do with the quirkiness of Excel's dates/formats, but I feel it should be working. Any help or insight is great appreciated!

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by tom_19; 03-30-2017 at 03:54 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Date Format Issue

    Try formatting the cell(s) before you put the value(s) in them.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    08-12-2011
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Date Format Issue

    I did try that and got the same numeric result in the cell. Sorry, should've stated in my original post that I had also tried that.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Date Format Issue

    Any chance you could upload a sample workbook?

    Click on GO ADVANCED, scroll down and click Manage Attachments.

  5. #5
    Registered User
    Join Date
    08-12-2011
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Date Format Issue

    Uploaded to original post. I took out all other info except for Date column (and a few sample dates, I have way more than just those 4!) and removed any code not relevant to what I'm currently trying to accomplish.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Date Format Issue

    Does this do what you want?
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-12-2011
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Date Format Issue

    Oh my... Yes, thank you! I guess I should've simplified my thinking and tried to format like that. Seems like the obvious solution now and is easier than what I was trying to do.

    I still don't understand why other cells are formatted as General and appear correctly but using my code would not produce those same results, but I feel foolish for spending as much time on this as I did so I guess it's time to move on.

    Thanks again!

+ 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. Date Format Issue
    By nsprasad in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-09-2015, 02:30 AM
  2. Replies: 4
    Last Post: 04-29-2015, 08:36 AM
  3. [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
  4. Date format issue
    By skhari in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-03-2012, 02:08 AM
  5. Date format issue
    By LadyDoe in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-17-2005, 04:00 AM
  6. Date format issue
    By DanielHurtubise in forum Excel General
    Replies: 2
    Last Post: 09-21-2005, 02:05 PM
  7. Date Format Issue
    By Mikeice in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-02-2005, 06:54 PM

Tags for this Thread

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