Aesop
Jr. Member

Karma: +1/-0
Offline
Mood:
Gender: 
Posts: 13
Topic starter
|
 |
« 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?
|
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 » |
Quote
|
|
|
|
|
|
Logged
|
|
|
|
KGIII
Official Code Wrecker
Administrator
Dedicated Poster
      
Karma: +15/-2
Offline
Mood:
Gender: 
OS: Vista, XP, Ubuntu
CPU: 2x AMD64 4800+
RAM: 3 GB
HDD: 500 GB (Raid0)
Posts: 11279
Yes, yes I can.
|
 |
« 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.)
|
|
|
|
|
Aesop
Jr. Member

Karma: +1/-0
Offline
Mood:
Gender: 
Posts: 13
Topic starter
|
 |
« 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.
|
There are 10 kinds of people in the world: those who understand binary, and those who don't.
|
|
|
|
runswithscissors
|
 |
« 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?
|
|
|
|
|
|
runswithscissors
|
 |
« 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.
|
|
|
|
|
|
Gł Solutions - Technology Defined
|
 |
« Reply #4 on: January 02, 2007, 11:18:27 AM » |
Quote
|
|
|
|
|
|
Logged
|
|
|
|
Aesop
Jr. Member

Karma: +1/-0
Offline
Mood:
Gender: 
Posts: 13
Topic starter
|
 |
« 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.
|
There are 10 kinds of people in the world: those who understand binary, and those who don't.
|
|
|
|
runswithscissors
|
 |
« 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. 
|
|
|
|
|
KGIII
Official Code Wrecker
Administrator
Dedicated Poster
      
Karma: +15/-2
Offline
Mood:
Gender: 
OS: Vista, XP, Ubuntu
CPU: 2x AMD64 4800+
RAM: 3 GB
HDD: 500 GB (Raid0)
Posts: 11279
Yes, yes I can.
|
 |
« Reply #7 on: January 02, 2007, 06:32:18 PM » |
|
*watches*
|
|
|
|
|
|
runswithscissors
|
 |
« 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.
|
|
|
|
|
|
runswithscissors
|
 |
« 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.
|
|
|
|
|
KGIII
Official Code Wrecker
Administrator
Dedicated Poster
      
Karma: +15/-2
Offline
Mood:
Gender: 
OS: Vista, XP, Ubuntu
CPU: 2x AMD64 4800+
RAM: 3 GB
HDD: 500 GB (Raid0)
Posts: 11279
Yes, yes I can.
|
 |
« 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.
|
|
|
|
|
|
4fit?
|
 |
« 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. =TEXT(A2*29,"mmm") If you want to return the whole month name, use: =TEXT(A2*29,"mmmm")
|
|
|
|
KGIII
Official Code Wrecker
Administrator
Dedicated Poster
      
Karma: +15/-2
Offline
Mood:
Gender: 
OS: Vista, XP, Ubuntu
CPU: 2x AMD64 4800+
RAM: 3 GB
HDD: 500 GB (Raid0)
Posts: 11279
Yes, yes I can.
|
 |
« 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?
|
|
|
|
|
|
4fit?
|
 |
« Reply #13 on: January 15, 2007, 03:25:39 PM » |
|
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. =DATE(YEAR(A2),A2,1)
|
|
|
|
KGIII
Official Code Wrecker
Administrator
Dedicated Poster
      
Karma: +15/-2
Offline
Mood:
Gender: 
OS: Vista, XP, Ubuntu
CPU: 2x AMD64 4800+
RAM: 3 GB
HDD: 500 GB (Raid0)
Posts: 11279
Yes, yes I can.
|
 |
« 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.
|
|
|
|
|
|
4fit?
|
 |
« Reply #15 on: January 15, 2007, 04:34:36 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.
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: Function GetMonthName(MonthNum As Integer) GetMonthName = MonthName(MonthNum, True) End Function Then you could use it in a cell like: =getmonthname(A1)
|
|
|
|
KGIII
Official Code Wrecker
Administrator
Dedicated Poster
      
Karma: +15/-2
Offline
Mood:
Gender: 
OS: Vista, XP, Ubuntu
CPU: 2x AMD64 4800+
RAM: 3 GB
HDD: 500 GB (Raid0)
Posts: 11279
Yes, yes I can.
|
 |
« Reply #16 on: January 15, 2007, 05:14:56 PM » |
|
We need a "that is over my head without a book" emoticon.
|
|
|
|
|
|
runswithscissors
|
 |
« 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. 
|
|
|
|
|
|
4fit?
|
 |
« 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.  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: 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.
|
|
|
|
|
4fit?
|
 |
« 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.
|
|
|
|
|