+ Reply to Thread
Results 1 to 8 of 8

Stop Excel from assuming data is a date

Hybrid View

carsto Stop Excel from assuming data... 10-03-2014, 09:35 AM
mikerickson Re: Stop Excel from assuming... 10-03-2014, 09:48 AM
Rioran Re: Stop Excel from assuming... 10-03-2014, 09:54 AM
Speshul Re: Stop Excel from assuming... 10-03-2014, 09:54 AM
Rioran Re: Stop Excel from assuming... 10-03-2014, 10:14 AM
carsto Re: Stop Excel from assuming... 10-03-2014, 11:29 AM
Rioran Re: Stop Excel from assuming... 10-03-2014, 11:48 AM
dlow Re: Stop Excel from assuming... 10-03-2014, 12:10 PM
  1. #1
    Forum Contributor
    Join Date
    08-14-2006
    Location
    USA
    MS-Off Ver
    2019
    Posts
    686

    Stop Excel from assuming data is a date

    I’m opening an output file from a design software program using the GetOpenFilename Method. Several of the cells have data like 1/4.

    Sometimes 1/4 means text “1/4”
    Sometimes 1/4 means a fraction one-fourth.
    In all cases Excel decides it means January 4th.

    Even when I open it manually using Data > From Text and select Column Data Format = Text Excel still decides it means January 4th.

    Is there any way to force Excel to leave it as 1/4?

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Stop Excel from assuming data is a date

    A work-around solution would be to (after import)

    For each oneCell in myRange
        With oneCell
            If IsDate(.Value) Then
                .Value = Month(.Value)/Day(.Value)
            End If
        End With
    Next oneCell
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Forum Contributor
    Join Date
    09-26-2014
    Location
    Moscow, Russia
    MS-Off Ver
    MSE 10, MSE 13
    Posts
    179

    Re: Stop Excel from assuming data is a date

    Carsto, hello.

    You may force Excel to interact with values as with totally stringy ones by adding ' symbol before. Just like in this example:

    Cells(2, 1).Value = "'" & Cells(1, 1).Value
    Best wishes and have a nice day!

  4. #4
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Stop Excel from assuming data is a date

    I have had this problem as well. When I enter a list of numbers in a AAA1111 format, and a value happens to be something like;
    JUN4826 or JUL3892
    it turns into
    Jun-26 or JUL-92
    Which are recognized as the values
    07/01/4826 or 07/01/3892
    Resulting in the numeric values
    1068883 or 727747

    Which is really annoying.

    One way around it is to format the entire column as TEXT before entering the data, and if copying data from another sheet make sure you Paste Special / Values

    OR, you can place a ' before the string

    '1/4 will show in the cell as 1/4 regardless of format


    Edit: Sorry, didn't notice this was in the VBA section. See above responses!
    You should hit F5, because chances are I've edited this post at least 5 times.
    Example of Array Formulas
    Quote Originally Posted by Jacc View Post
    Sorry, your description makes no sense. I just made some formula that looks interesting cause I had nothing else to do.
    Click the * below on any post that helped you.

  5. #5
    Forum Contributor
    Join Date
    09-26-2014
    Location
    Moscow, Russia
    MS-Off Ver
    MSE 10, MSE 13
    Posts
    179

    Re: Stop Excel from assuming data is a date

    Speshul, hello.

    Don't mind about section, your idea about cell formating sounds good =) Because everything that we might do manually - may be performed by code.

    So, by VBA we may change cell formating to text. Could be better to change every single cell, because whole column will eat PC resources.

    Cells(2, 1).NumberFormat = "@"
    Cells(2, 1).Value = "1/4"

  6. #6
    Forum Contributor
    Join Date
    08-14-2006
    Location
    USA
    MS-Off Ver
    2019
    Posts
    686

    Re: Stop Excel from assuming data is a date

    I should have been clearer. Some of the data in the TEXT FILE is like 1/4, once it's opened in Excel it's no longer stored as 1/4, it's Jan 4 2014.

    With the GetOpenFilename Method the file just opens in a new workbook, there is no opportunity to preformat the cells.
    I have to find a way for excel to stop guessing at the cell format and load everything as text.


    mikerickson - thanks, that's what I've been doing when in needs changed to a decimal.
    (when it's really text "1/4", meaning section 1 / subsection 4, I put the month/section in 1 column and the day/subsection in a second column as a permanent fix)

    Rioran - once it's opened in excel it's no longer stored as 1/4, it's Jan 4 2014 so your formula changes it to '1/4/2014

  7. #7
    Forum Contributor
    Join Date
    09-26-2014
    Location
    Moscow, Russia
    MS-Off Ver
    MSE 10, MSE 13
    Posts
    179

    Re: Stop Excel from assuming data is a date

    Carsto, o'key, I see then what we might do. May you please attach sample of your TXT file? 10-20 rows with different cases will be sufficient.

  8. #8
    Forum Contributor dlow's Avatar
    Join Date
    08-12-2013
    Location
    EveryWhere
    MS-Off Ver
    Excel 2007, 2010
    Posts
    275

    Re: Stop Excel from assuming data is a date

    Hi,

    I think you will have to write an if statement to deal with this [if text, or if fraction] something like this:
    =IF(AVERAGE(V2,W2,X2,Y2)>1,TEXT(AVERAGE(V2,W2,X2,Y2),"###,###.00"),TEXT(AVERAGE(V2,W2,X2,Y2),".0000#")). Without looking @ the data I dont know how I would do it, but that is what I would try do to solve my problem. Like everyone mentioned you can force Excel to see the data as text by inserting a leading comma that would keep Excel from changing the vale on you.
    Custom Number Formats, Date & Time Formats in Excel & VBA; NumberFormat property

    All the best & good luck

+ 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] Excel 2007 : graphing a continuous data series/assuming zeros
    By Taft584 in forum Excel General
    Replies: 5
    Last Post: 04-29-2012, 05:43 PM
  2. Replies: 1
    Last Post: 04-18-2012, 05:49 PM
  3. String assuming date format
    By humantripod in forum Excel General
    Replies: 2
    Last Post: 12-13-2006, 06:36 PM
  4. stop changing data to date
    By Sara in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 02-09-2005, 04:06 PM
  5. [SOLVED] Excel Date Format - Stop?
    By Bob in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-10-2005, 10: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