简体   繁体   English

Excel中的连续月份计数公式

[英]Continuous month count formula in Excel

I want to make continues month list starting from specific date in English. 我要从英语的特定日期开始制作连续月份列表。 Lets say my date is 29.4.2019 . 可以说我的约会日期是29.4.2019 I would like Excel formula to display months in English starting from that date, so my list would look like (by dropping down): 我希望Excel公式从该日期开始以英语显示月份,所以我的列表看起来像(通过下拉列表):

May
July
August
September
October
November
December
January
February
etc...

I have tried this formula but it ends up on December, also I have to input +1, +2, +3 manually: 我已经尝试过此公式,但最终会在12月结束,也必须手动输入+1, +2, +3

=CHOOSE(MONTH(A1)+1;"January";"February";"March";"April";"May";"July";"August";"September";"October";"November";"December")

Also the problem is that I use Finnish Excel so function should be =TEXT(MONTH(A1);"kkkk") instead of =TEXT(MONTH(A1);"mmmm") if I want to use more simple version with =TEXT function. 另外的问题是,我使用芬兰语Excel,因此如果我想对=TEXT使用更简单的版本,则函数应为=TEXT(MONTH(A1);"kkkk")而不是=TEXT(MONTH(A1);"mmmm")功能。 However this will not work once Excel will be opened on English version of Excel as it will not recognize "kkkk" inside the formula and will give an error. 但是,一旦在英语版本的Excel上打开Excel,这将无法正常工作,因为它将无法识别公式中的“ kkkk”,并且会出现错误。

I have VBA to convert to international format but this does not seem to work either ( https://superuser.com/questions/730371 ). 我已经将VBA转换为国际格式,但这似乎也不起作用( https://superuser.com/questions/730371 )。

Public Function FMT$(ByVal Value, ByVal strFormat)
    FMT = VBA.Format$(Value, strFormat)
End Function

EDIT: 编辑:

Ok. 好。 That was stupid mistake... I skipped "June" in my list. 那是愚蠢的错误...我在清单中跳过了“六月”。 This function seems to be working now: 此功能现在似乎可以正常工作:

=CHOOSE(MONTH(A1)+1;"January";"February";"March";"April";"May";"June";"July";"August";"September";"October";"November";"December")

I guess you could try the following: 我想您可以尝试以下方法:

=IF(C1="";TEXT($A$1;"kkkk");TEXT(DATE(YEAR($A$1);1+MONTH("1-"&C1&"-"&YEAR($A$1));1);"kkkk"))

在此处输入图片说明

The above formula basically uses two branches of the IF (you might have to pick a more appropriate condition depending on the layout of your excel sheet and where you need the results to be, but without knowing that, that's the best I can offer). 上面的公式基本上使用了IF两个分支(您可能不得不根据excel工作表的布局以及所需结果的位置选择一个更合适的条件,但不知道那是我能提供的最好的条件)。

So basically if it's the first one, the cell directly above will be blank, so the formula will be simply TEXT($A$1,"kkkk") . 因此,基本上,如果它是第一个,则其正上方的单元格将为空白,因此公式将仅为TEXT($A$1,"kkkk") If there's a value, then we need to add one month, and to do that as accurate as possible, I would use DATE(YEAR($A$1),1+MONTH("1-"&C1&"-"&YEAR($A$1)),1) , which basically takes the year of the date supplied in A1, the month following the previous month, and 1 as the date. 如果有一个值,那么我们需要添加一个月,并尽可能精确地做到这一点,我将使用DATE(YEAR($A$1),1+MONTH("1-"&C1&"-"&YEAR($A$1)),1) ,基本上是将A1中提供的日期的年份,上个月的下个月以及日期作为1。 Excel can understand the format d-mmmm-yyyy as date, so I'm taking advantage of that. Excel可以将d-mmmm-yyyy格式理解为日期,因此我可以利用这一点。


Not using TEXT : 不使用TEXT

=CHOOSE(IF(C1="";MONTH($A$1);MOD(MONTH("1-"&C1&"-"&YEAR($A$1));12)+1);"January";"February";"March";"April";"May";"June";"July";"August";"September";"October";"November";"December")

With the smallest possible change from how your own code works: 对您自己的代码的工作方式进行最小的更改:

=CHOOSE(MOD(MONTH($A$1)+Row()-2, 12)+1, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")

First, the +Row()-2 means that you no longer need to type the +1 , +2 , +3 manually - it will use the Row number that the cell is on. 首先, +Row()-2意味着您不再需要手动输入+1+2+3 3-它会使用该单元格所在的行号。 (Depending on which row your list starts on, you may need to adjust the -2 ) (取决于列表从哪一行开始,您可能需要调整-2

Next, we use Mod(<adjusted month>,12) - this means, every time we reach 12, it resets back to 0: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, ... 接下来,我们使用Mod(<adjusted month>,12) -这意味着,每次达到12时,它将重置为0: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, ...

Finally, add 1. 最后,添加1。

If we start in December, and the formula is in row 2 then we get MOD(Month("2018-12-01")+Row()-2, 12)+1 , which becomes MOD(12 + 2 - 2, 12) + 1 or MOD(12, 12) + 1 and finally 0 + 1 . 如果我们从12月开始,并且公式在第2行中,则得到MOD(Month("2018-12-01")+Row()-2, 12)+1 ,即为MOD(12 + 2 - 2, 12) + 1MOD(12, 12) + 1 ,最后是0 + 1
The next item will be on Row 3, so MOD(Month("2018-12-01")+Row()-2, 12)+1 becomes MOD(12 + 3 - 2, 12) + 1 or MOD(13, 12) + 1 and finally 1 + 1 for February. 下一项将在第3行上,因此MOD(Month("2018-12-01")+Row()-2, 12)+1变为MOD(12 + 3 - 2, 12) + 1MOD(13, 12) + 1 ,最后是2月的1 + 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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