+ Reply to Thread
Results 1 to 18 of 18

Dates to String but Cell formatted as Number

  1. #1
    Registered User
    Join Date
    09-17-2013
    Location
    East
    MS-Off Ver
    Excel 2010
    Posts
    55

    Question Dates to String but Cell formatted as Number

    Hey there,

    I have a weired problem. I'm working on a sheet for our accounting section which has been in use for quite some time, which means, that I'm not supposed to change a hell of a lot in it since it's accounting and everybody is afraid of changes.

    Coming to the point, I have the following problem:

    (1) I have a date.
    (2) I need that date in this format: "mm-yyyy", written in a certain cell.
    (3) BUT: the cell should NOT contain the date itself, but JUST the text (some tables in the background need this format)
    (4) Changing the cell to text-format is not eligible, since it puts an " ' " in front of the numbers.
    (5) The cell should be formatted as a number.

    So, in conclusion:
    I need a string/number with the date in this format: "mm-yyyy" in the cell formated .NumberFormat = "0".


    I know it's weired but as I said, I'm working on an existing workbook...

    Any help is greatly appreciated!

    Cheers,
    Klaster


    Edit: I decided to add some code and a screenshot. This code will return the number, which lies behind the date, and write it into the cell. So that's not what I want, but maybe the code helps clearifying what I need anyway.

    The screenshot shows the wanted output.


    Please Login or Register  to view this content.
    screenie.png
    Last edited by Klaster; 02-11-2014 at 07:16 AM. Reason: added code and screenie

  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: Dates to String but Cell formatted as Number

    What dates do you want in mmm-yyy format?

    Do you need code?

    You could use the TEXT worksheet function.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    09-17-2013
    Location
    East
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Dates to String but Cell formatted as Number

    Quote Originally Posted by Norie View Post
    What dates do you want in mmm-yyy format?

    Do you need code?

    You could use the TEXT worksheet function.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Hey Norie,
    thanks for your reply.

    The dates are set as the project's time horizon in another sheet and I add rows to match the time frame (e.g. project: 01-2014 to 05-2014, I need rows with all the months in between). That means that the date is variable. Anyway, I could write the date invisible in some cell.
    I tried you function and get the following result (Z1911 is formatted as date):

    screenie2.png

    After all, I'd prefer a code-based solution, though...

    Thanks!

  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: Dates to String but Cell formatted as Number

    It's still not clear what you want to do.

    Can you upload an example workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

  5. #5
    Registered User
    Join Date
    09-17-2013
    Location
    East
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Dates to String but Cell formatted as Number

    Hey Norie,

    I created an example workbook and attached it.

    A few marks:
    Sheet "Team": type in time frame (start and end month)
    Sheet "Leistungsliste": Column D is the crucial part here. You can see that the cells are formatted as numbers and show "10-2011".

    My code will add a block for every month, when the project horizon is extended. Therefore, I edit the "block" in sheet "Tabelle2". I want the cells in Col D to be exactly like the existing ones in "Leistungsliste". I cast the dates from sheet "Team", calculate how many new blocks I need (<-> how many months need to be added) and copy&paste the block accordingly (hence I edit Col D everytime before I copy&paste it).

    I hope it's more understandable now?

    playground_example.xlsm

  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: Dates to String but Cell formatted as Number

    Should I be entering dates in G5 and H5?

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

    Re: Dates to String but Cell formatted as Number

    Try this - I was missing a y and had too many ms.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    09-17-2013
    Location
    East
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Dates to String but Cell formatted as Number

    Quote Originally Posted by Norie View Post
    Try this - I was missing a y and had too many ms.
    Please Login or Register  to view this content.
    I tried that before, but the NumberFormat of the cell needs to be "0", because the text-Format automatically puts a " ' " in front of the text. That means, that it looks the same, but it is actually not the same... I need it to be exact because other tables use the information for further calculating.

    Isn't it possible to somehow "hard code" the date as a number?

    Sth like the following... but this gives me a "40848" etc. Why can't I just get the month and year as hard strings that won't change back to date-format when entered in the cell?!?!

    Please Login or Register  to view this content.

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

    Re: Dates to String but Cell formatted as Number

    Unfortunately when you enter 10-2011 in a cell format as general then Excel sees it as a date so it converts it to one.

    Try it yourself by entering 02-2014 in a cell.

    How are the further calculations being affected by the '?

    If they are perhaps it's best to keep the dates as 'real' dates, use formatting to display them as mm-yyyy and adjust formulas appropriately.

  10. #10
    Registered User
    Join Date
    09-17-2013
    Location
    East
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Dates to String but Cell formatted as Number

    Quote Originally Posted by Norie View Post
    Unfortunately when you enter 10-2011 in a cell format as general then Excel sees it as a date so it converts it to one.

    Try it yourself by entering 02-2014 in a cell.

    How are the further calculations being affected by the '?

    If they are perhaps it's best to keep the dates as 'real' dates, use formatting to display them as mm-yyyy and adjust formulas appropriately.

    Yes, I though the same, but as I said, the workbook already exists in that way. I have no idea how they managed to get the format as it is in sheet "leistungsliste" Col D...

    There are some PivotTables in the background, that seem to be unable to deal with the '01-2014 - format. I guess I'll need to make some greater changes to the workbook after all.


    Thanks anyway for your help - very much appreciated!

    I won't mark the thread solved - who knows if somebody comes up with a magic solution...

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

    Re: Dates to String but Cell formatted as Number

    I would have thought it would be better for pivot tables if the data included 'real' dates.

    That would allow for grouping by month/year and proper chronological sorting.

    PS As far as I can see the existing data on the 'Leistungsliste' sheet also has the ' in front of the dates.

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

    Re: Dates to String but Cell formatted as Number

    How about putting a formula in the column?
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    09-17-2013
    Location
    East
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Dates to String but Cell formatted as Number

    Quote Originally Posted by Norie View Post
    How about putting a formula in the column?
    Please Login or Register  to view this content.

    That gives me the same as shown in the 2nd screenshot, I posted above (see "screenie2"). Another screenshot is attached:

    formula.png

    and the one from above

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

    Re: Dates to String but Cell formatted as Number

    Instead of mm-yyyy have you tried tt-jjjj?

  15. #15
    Registered User
    Join Date
    09-17-2013
    Location
    East
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Dates to String but Cell formatted as Number

    Quote Originally Posted by Norie View Post
    Instead of mm-yyyy have you tried tt-jjjj?
    Good call. tt-jjjj works great but obviously shows the day and year. mm-jjjj doesn't seem to work though?!

    formula.png

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

    Re: Dates to String but Cell formatted as Number

    Clutching at straws now.

    How about this?
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    09-17-2013
    Location
    East
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Dates to String but Cell formatted as Number

    Hey,

    sorry for my late reply.
    I'll talk with the guy who created the workbook in the first place soonish and hope that he'll shed some light on the issue.

    Thanks for your effort! It's really appreciated!

  18. #18
    Registered User
    Join Date
    09-17-2013
    Location
    East
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Dates to String but Cell formatted as Number

    Just as a little follow-up: turns out, the background mechanisms also work with the '01-2014 -Format. Still a strange issue though.

    Thanks again for all the help.

+ 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. Extracting numbers and text from inconsistent text/number formatted string
    By Brandivil in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-25-2013, 01:46 PM
  2. Replies: 16
    Last Post: 10-11-2011, 12:31 PM
  3. Convert Formatted Number to String
    By Rob169 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-24-2007, 12:35 PM
  4. [SOLVED] Formatted Number into String Variable, Excel VBA
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-16-2006, 07:25 PM
  5. How to make a cell return the formatted value in a text string (i.
    By n.almeida in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-02-2005, 10:06 AM

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