简体   繁体   中英

Easier way to spell out Month and Day based on a numeric cell input

In the header for one of my spreadsheets I have to type "For the X Months Ended MMMMMM DD, YYYY" where X is the number of the month spelled out in English (IE 'Twelve').

The date in question is always the last day of the period. The period is defined in a cell in numeric form (for use in formulae). For example, October is period 1. So what I did to automate this was the following monstrous formula using the workbook name and 3 named ranges as 'helpers':

="For the " & INDEX(MonthNumbers,MATCH(INDEX(PeriodMonths,'Franchise Fees'!U2,),CalendarMonths,0)) & " Months Ended " & TEXT(DATE(MID(CELL("Filename",A1),SEARCH("_",CELL("Filename",A1))-4,4),MOD('Franchise Fees'!U2+10,12),1)-1,"MMMMMMMMM DD, YYYY")

MonthNumbers is just a list of the numbers 1-12 in English (One, Two,...)

PeriodMonths is the list of month names offset by 10 months (so that 1 = October)

CalendarMonths is the list of month names in normal order (so that 1 = January)

Now, I'm proud of this formula, but once my boss sees it she is going to flip out (she hates long formulae). So I need to ask:

Is there a simpler way to do this? It feels like there should be. Also, I CANNOT use VBA. This is a macro-free workbook.

You could use a custom format and just have to type in the date. Right-click the cell, choose Format Cells... and fill in this Custom Format:

"For the month ended" mmmm dd, yyyy

在此处输入图片说明

You could of course use a shorter version of your formula to figure the date.

I rather agree with your boss. A 247 character formula does not seem particularly well-suited for the results required.

I would suggest something like two versions of the same (18 character) formula:

=VLOOKUP(A1,T,2,0)  

and the same again with 2 replaced by 3 (where A1 is the entered month number).

Keep the lookup table (named T by me - not best practice, but short!) and extend it to include the month-end dates (calculated, if you wish) properly aligned (so October is in the same row (or column if you prefer HLOOKUP instead of VLOOKUP) as 1 and one .

The stumbling block however might be that I would use four cells for the output, the first with For the the third with Months Ended (these don't change, so why include them in a formula?), the other two with the LOOKUP formulae and suitable formatting.

If you must have all this in a single cell (and don't mind the oddity of "one Months") then the following might be preferred:

="For the "&VLOOKUP(A1,T,2,0)&" Months Ended " &TEXT(VLOOKUP(A1,T,3,0),"mmmm dd, yyy")  

that is also regrettably long, but at least is considerably less long.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM