August 30, 2008, 07:58:02 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

There are currently 0" users in chat
News: Would you like to make a suggestion? Feel free to do so.
 
 
  Website   Home   Help Search Affiliate Chat Calendar Members Tags Links Gallery Media Center Login Register  
Gł Solutions Network
In short, the goal of Gł Solutions is in the title. We attempt to define technology in easily understood terms.
From the end-user to the entrenched and battle scarred professional - we all have questions. And answers.
We attempt to answer these questions - in a round-about fashion - as this: "How can technology help?"
MAIN SITE BLOG Main Site Search HOSTING PRIVACY CONTACT ABOUT



Digg This!
Subject Statistics
Topic: Excel date formatting Replies: 23 posts
Read 1643 times 0 Members and 1 Guest are viewing this topic.
Pages: [1] 2  All   Go Down
  Reply  |  New Topic  |  Send this topic  |  Print  
Author Topic: Excel date formatting  (Read 1643 times)
 
0 Members and 1 Guest are viewing this topic.
Aesop
Jr. Member
**

Karma: +1/-0
Offline Offline

Mood:

Gender: Male
Posts: 13


Aries   White Wind - Communicates SpiritMagnetic

Topic starter

View Profile
« on: January 02, 2007, 09:12:24 AM »

This seems like it should be a simple thing, but...

I have a column in Excel that has the month represented as an integer (1-12).  Ideally, I'd like to have it show the abbreviated month name (1 = Jan, 2 = Feb, etc.).

But.

If I try to change the cell formatting (like, for example, using the "mmm" mask), it changes the cell content from an integer (12) to a date (1/12/1900).  Likewise if I try to use a TEXT conversion. 

Is there a way of going from integer to month literal without using an extended IF statement?
Report to moderator   Logged

There are 10 kinds of people in the world:  those who understand binary, and those who don't.
Gł Solutions - Technology Defined
« on: January 02, 2007, 09:12:24 AM »
Reply with quoteQuote


 Logged
KGIII
Official Code Wrecker
Administrator
Dedicated Poster
********

Karma: +15/-2
Offline Offline

Mood:

Gender: Male
OS: Vista, XP, Ubuntu
CPU: 2x AMD64 4800+
RAM: 3 GB
HDD: 500 GB (Raid0)
Posts: 11279


 

Yes, yes I can.


View Profile WWW
« Reply #1 on: January 02, 2007, 10:15:27 AM »

Is there a way of going from integer to month literal without using an extended IF statement?

My version of Excel is likely different than the one you are using, 2k7, and in it the closest I can THINK of (my skills with Excel are not that high) is under formulas and is in the Date and Time and the "mmm" value by itself to format the cell? The paths to get to it would be so entirely different that any screenshot I took or tried to describe (Have I mentioned I hate the ribbon?) will be entirely pointless to you I suspect but I did get it to output a "Jan" for 1 which was more than I'd expected I'd get. (After getting it to mmm-yy I figured that might be it.)
Report to moderator   Logged
Aesop
Jr. Member
**

Karma: +1/-0
Offline Offline

Mood:

Gender: Male
Posts: 13


Aries   White Wind - Communicates SpiritMagnetic

Topic starter

View Profile
« Reply #2 on: January 02, 2007, 11:02:38 AM »

...but I did get it to output a "Jan" for 1 which was more than I'd expected I'd get. (After getting it to mmm-yy I figured that might be it.)
I think you picked the one example where this does work; otherwise, not so much.  Formatting the cell this way changes the integer to a date and the "mmm" then just shows the month portion of the date.  So the integer '1' changes to '1/1/1900', which works just fine, but the integer '12' changes to '1/12/1900', which then displays as the month 'Jan'.  Not so good.

I decided to use the "choose" function, mostly because I've never used it before.  It's not as elegant as I might have wished, but it does work, so it has that going for it.

But thanks for thinking about this.
Report to moderator   Logged

There are 10 kinds of people in the world:  those who understand binary, and those who don't.
runswithscissors
Helpers
Dedicated Poster
********

Karma: +3/-0
Offline Offline

Mood:

Gender: Female
Posts: 1061


Libra  

Insert Wit Here


View Profile
« Reply #3 on: January 02, 2007, 11:15:49 AM »

Damn. Wish I'd been awake earlier. Excel is something I'm quite familiar with.

So, you did get it to work?
Report to moderator   Logged
runswithscissors
Helpers
Dedicated Poster
********

Karma: +3/-0
Offline Offline

Mood:

Gender: Female
Posts: 1061


Libra  

Insert Wit Here


View Profile
« Reply #4 on: January 02, 2007, 11:18:27 AM »

Well, for future reference, I always do this:

Highlight the cell/row/column you want the formula to work in, right click to bring up the quick menu, then choose "format cells."

From there choose the date function, and it has a lot of different options. The "14-Mar" one is the function you're looking for, I believe.
Report to moderator   Logged
Gł Solutions - Technology Defined
« Reply #4 on: January 02, 2007, 11:18:27 AM »
Reply with quoteQuote


 Logged
Aesop
Jr. Member
**

Karma: +1/-0
Offline Offline

Mood:

Gender: Male
Posts: 13


Aries   White Wind - Communicates SpiritMagnetic

Topic starter

View Profile
« Reply #5 on: January 02, 2007, 11:40:14 AM »

I may not have explained my situation clearly.

In column A I have integers 1-12 representing months.  I want to keep them as integers.  Then I want to do one of two things. 
a) I want column A to display as the month literal; or
b) I want to display the corresponding month literal in column B.

Now, in theory, formatting the cells in column A would seem to do the trick.  But I'm finding that formatting changes the cells from integer to date, so an integer of 1 becomes a date of 1/1/1900, and an integer of 12 becomes a date of 1/12/1900.  This is no good.  Using formatting commands like 'TEXT' in column B also seems to have the same problem.

So, instead I'm using the 'CHOOSE' function:  =CHOOSE(A312,"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec").  This works insofar as it lets me keep the A column as an integer and it displays the month literal in column B. It just seems a bit inelegant.

Anyway, none of this is really important.  It just seems like one of those things that should be easier to do.
Report to moderator   Logged

There are 10 kinds of people in the world:  those who understand binary, and those who don't.
runswithscissors
Helpers
Dedicated Poster
********

Karma: +3/-0
Offline Offline

Mood:

Gender: Female
Posts: 1061


Libra  

Insert Wit Here


View Profile
« Reply #6 on: January 02, 2007, 11:46:44 AM »

Ah, I see what you're saying. Hmmm... yes, anytime you want to keep an integer, yet display something else, you do have to resort to a formula for it.

I'll play with it for a bit, but you may have what you need there.

Of course it's important... hey now I know how to do it. Tongue
Report to moderator   Logged
KGIII
Official Code Wrecker
Administrator
Dedicated Poster
********

Karma: +15/-2
Offline Offline

Mood:

Gender: Male
OS: Vista, XP, Ubuntu
CPU: 2x AMD64 4800+
RAM: 3 GB
HDD: 500 GB (Raid0)
Posts: 11279


 

Yes, yes I can.


View Profile WWW
« Reply #7 on: January 02, 2007, 06:32:18 PM »

*watches*
Report to moderator   Logged
runswithscissors
Helpers
Dedicated Poster
********

Karma: +3/-0
Offline Offline

Mood:

Gender: Female
Posts: 1061


Libra  

Insert Wit Here


View Profile
« Reply #8 on: January 02, 2007, 08:36:29 PM »

And now I'm nervous.

Quit looking at me!

I still haven't played around with it yet. I'll do that whilst I eat dinner.
Report to moderator   Logged
runswithscissors
Helpers
Dedicated Poster
********

Karma: +3/-0
Offline Offline

Mood:

Gender: Female
Posts: 1061


Libra  

Insert Wit Here


View Profile
« Reply #9 on: January 02, 2007, 09:43:24 PM »

Ok, I played around with it, and... your way works best. LOL!

Sorry... it's either CHOOSE or an IF formula that would be so complicated my head would spin.
Report to moderator   Logged
KGIII
Official Code Wrecker
Administrator
Dedicated Poster
********

Karma: +15/-2
Offline Offline

Mood:

Gender: Male
OS: Vista, XP, Ubuntu
CPU: 2x AMD64 4800+
RAM: 3 GB
HDD: 500 GB (Raid0)
Posts: 11279


 

Yes, yes I can.


View Profile WWW
« Reply #10 on: January 03, 2007, 12:33:02 AM »

I do have access to the Office dev. team via email/phone I understand. (I'd have too many choice words to say to them for a voice call.) If your way works then that's good, if there really is much of a call for it then, well, it's easy enough to file a feature request/improvement.

For those not in on the beta process and seeing the newer stuff, it should be interesting. It really should. Office 2k7 is going to take a little acclimation time but, for the most part, it does seem likely that people who use it often will speed up because of the changes. I, on the other hand, will still have to poke around until I find stuff.
Report to moderator   Logged
4fit?
Full Member
***

Karma: +2/-0
Offline Offline

Mood:

Gender: Male
Posts: 36


Gemini   White Dog - Loves HeartElectric

That guy.......4fit?


View Profile WWW
« Reply #11 on: January 15, 2007, 02:21:13 PM »

Just joined the forum, so I am probably a day late and a dollar short, but. . . . . . . . .

This formula will do what you want.
Code:
=TEXT(A2*29,"mmm")

If you want to return the whole month name, use:
Code:
=TEXT(A2*29,"mmmm")
Report to moderator   Logged

Mustangs Of Burlington Admin

Specialize in MS Office Automation
KGIII
Official Code Wrecker
Administrator
Dedicated Poster
********

Karma: +15/-2
Offline Offline

Mood:

Gender: Male
OS: Vista, XP, Ubuntu
CPU: 2x AMD64 4800+
RAM: 3 GB
HDD: 500 GB (Raid0)
Posts: 11279


 

Yes, yes I can.


View Profile WWW
« Reply #12 on: January 15, 2007, 03:00:45 PM »

Bah, he'll see it I'm sure. But will that keep them as integers?
Report to moderator   Logged
4fit?
Full Member
***

Karma: +2/-0
Offline Offline

Mood:

Gender: Male
Posts: 36


Gemini   White Dog - Loves HeartElectric

That guy.......4fit?


View Profile WWW
« Reply #13 on: January 15, 2007, 03:25:39 PM »

Quote from: KGIII link=topic=382.   msg2379#msg2379 date=1168891245
Bah, he'll see it I'm sure.    But will that keep them as integers?
He mentioned that he would be fine with the integers in column A and the names in column B.  If this formula is placed in column B, the integers won't be changed at all.
You could also use the below forumla and change the fomatting of the cell to "mmm" for abbreviated month or "mmmm" for the whole name.  The year really doesn't matter though.  You could key in 1999 and get the same outcome.  I just think it's cleaner if you use the year of the cell you are referencing. 
Code:
=DATE(YEAR(A2),A2,1)
Report to moderator   Logged

Mustangs Of Burlington Admin

Specialize in MS Office Automation
KGIII
Official Code Wrecker
Administrator
Dedicated Poster
********

Karma: +15/-2
Offline Offline

Mood:

Gender: Male
OS: Vista, XP, Ubuntu
CPU: 2x AMD64 4800+
RAM: 3 GB
HDD: 500 GB (Raid0)
Posts: 11279


 

Yes, yes I can.


View Profile WWW
« Reply #14 on: January 15, 2007, 04:24:14 PM »

Most excellent and, by the way, thanks and welcome to the forum. I'll bump you up over 10 posts so that you can actually be a "normal" member and post links and stuff.
Report to moderator   Logged
4fit?
Full Member
***

Karma: +2/-0
Offline Offline

Mood:

Gender: Male
Posts: 36


Gemini   White Dog - Loves HeartElectric

That guy.......4fit?


View Profile WWW
« Reply #15 on: January 15, 2007, 04:34:36 PM »

Quote from: KGIII link=topic=382. msg2382#msg2382 date=1168896254
Most excellent and, by the way, thanks and welcome to the forum.  I'll bump you up over 10 posts so that you can actually be a "normal" member and post links and stuff.
Thanks!!! 
Also, if you are using Excel 2000 and up, you could create a UDF in VBA and use the MonthName function to return the month name.
Something like this:
Code:
Function GetMonthName(MonthNum As Integer)
    GetMonthName = MonthName(MonthNum, True)
End Function

Then you could use it in a cell like:
Code:
=getmonthname(A1)
Report to moderator   Logged

Mustangs Of Burlington Admin

Specialize in MS Office Automation
KGIII
Official Code Wrecker
Administrator
Dedicated Poster
********

Karma: +15/-2
Offline Offline

Mood:

Gender: Male
OS: Vista, XP, Ubuntu
CPU: 2x AMD64 4800+
RAM: 3 GB
HDD: 500 GB (Raid0)
Posts: 11279


 

Yes, yes I can.


View Profile WWW
« Reply #16 on: January 15, 2007, 05:14:56 PM »

We need a "that is over my head without a book" emoticon.
Report to moderator   Logged
runswithscissors
Helpers
Dedicated Poster
********

Karma: +3/-0
Offline Offline

Mood:

Gender: Female
Posts: 1061


Libra  

Insert Wit Here


View Profile
« Reply #17 on: January 15, 2007, 07:31:19 PM »

Uhm, yes. I agree with KGIII... welcome to the board! And... I didn't understand the last part. Cheesy
Report to moderator   Logged
4fit?
Full Member
***

Karma: +2/-0
Offline Offline

Mood:

Gender: Male
Posts: 36


Gemini   White Dog - Loves HeartElectric

That guy.......4fit?


View Profile WWW
« Reply #18 on: January 15, 2007, 08:56:44 PM »

Uhm, yes. I agree with KGIII... welcome to the board! And... I didn't understand the last part. Cheesy
hehe
Thanks for the welcome!
VBA (Visual Basic for Applications) is the MS Office version of VB (Visual Basic).  Simply click Alt+F11 in your Excel window and you're there.  You can create userforms, modules, class modules, etc, etc.  Some really powerful things can be created in there.  In fact, I created an Excel add-in called X-Celleration for my company.  It automates many repeatative tasks in Excel and can perform operations in seconds that would take a user hours if not days to do manually.  There are currently more than 70 functions in the program. I am considering making a commercially available version.

The rest of the MS Office suite has VBA built in as well.  Trust me, if you ever take the time to learn it, you will become addicted to it!

Want to give it a shot?  Place some regular dates (ex 1/5/07, 12/31/98, etc) in column A.  Be sure to include a column header.  Then, press Alt+F11 to open VBA.  If the Project Explorer window is not visible on the left side, activate it by going to View-->Project Explorer.  Select your workbook from the Project Explorer list and go to Insert-->Module.  In the new window, paste in this code:
Code:
Sub ExcelToJulian()
    Dim NormDateYear As String, NormDateDay As String
    Dim Clm As String, BotRow As Long
    If Application.CountA(ActiveSheet.Cells) = 0 Then
        MsgBox "Worksheet is empty.  Can not proceed", , "Error"
        Exit Sub
    End If
    Clm = InputBox("Which column contains the standard dates?", "Column Entry")
    If Clm = "" Then Exit Sub
    BotRow = Range(Clm & "65536").End(xlUp).Row
    Range(Clm & "2").Offset(0, 1).EntireColumn.Insert
    Range(Clm & "2").Offset(-1, 1).Value = "JulianDate"
    For i = 0 To (BotRow - 2)
        If Not IsDate(Range(Clm & "2").Offset(i, 0)) Then
            Range(Clm & "2").Offset(i, 1).Value = "Not Date Format"
        Else
            NormDateYear = Format(Range(Clm & "2").Offset(i, 0), "yy")
            NormDateDay = Format(Str(Range(Clm & "2").Offset(i, 0) - _
                DateValue("1/1/" & Str(NormDateYear)) + 1), "000")
            Range(Clm & "2").Offset(i, 1).NumberFormat = "@"
            Range(Clm & "2").Offset(i, 1).Value = NormDateYear & NormDateDay
        End If
    Next i
End Sub

Now, return to Excel and go to Tools-->Macro-->Macros.  Select ExcelToJulian from the popup list and click Run.

Might seem like a lot of work for something so simple, but this one code gets ran over 100 times a day in my company, normally on worksheets containing 20000-30000 records.  Also, my program actually adds a menu to Excel, so you don't have to go through all the hoops to run the program.
Report to moderator   Logged

Mustangs Of Burlington Admin

Specialize in MS Office Automation
4fit?
Full Member
***

Karma: +2/-0
Offline Offline

Mood:

Gender: Male
Posts: 36


Gemini   White Dog - Loves HeartElectric

That guy.......4fit?


View Profile WWW
« Reply #19 on: January 15, 2007, 09:04:19 PM »

I have attached a spreadsheet containing the above code example.  When you first open the spreadsheet, you may receive a popup from Excel stating that the file contains macros, blah, blah.  Click Enable Macros. 

Click the Convert Excel Date To Julian Date button to launch the code.  The dates are in column A.

* VBAExample.zip (9.06 KB - downloaded 12 times.)
Report to moderator   Logged

Mustangs Of Burlington Admin

Specialize in MS Office Automation
Tags:
Pages: [1] 2  All   Go Up
  Reply  |  New Topic  |  Send this topic  |