动态更改一个月内的下载天数 [英] Dynamically change the number of days in a month for dropdown

查看:139
本文介绍了动态更改一个月内的下载天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

A1必须在没有VBA的情况下才能完成。



可以使用数据验证列表(=月)填充这些选项,导致在A1中显示一个下拉列表。在单元格B1中,输入年份号码(例如2000)。
现在我想要C1包含一个下拉列表,其中根据A1和B1中的数据进行更改的条目。在我的例子中,A1提供了一月,二月,三月,四月,六月,七月,八月,九月,十月,十一月和十二月的选择。



一月或三月,或可能或7月或8月或10月或12月(31天)的月份,我应该在C1之间取1到31之间的数字作为C1中的选项。



如果我选择四月或六月或九月或十一月(30天的月份),我应该在C1中选择1到30之间的数字。



如果我选择二月,我必须首先检查一个年份是否具有以下公式的闰年:

  =((MOD(B1; 4)= 0) *((MOD(B1; 100)0)+(MOD(B1; 400)= 0))= 1)

并根据此公式的结果(TRUE或FALSE),我应该获得1到28之间的数字(或29如果是闰年)作为C1中的选项。



我创建了名为Days30,Days31,Days28和Days29的列表。如何使用数据验证在这些列表之间切换我的C1?我试图将这个逻辑转化为数据验证公式,但没有运气:

 如果(A1 =april或A1 =juneOR A1 =9月OR A1 =november)然后
Days30
ElseIf(A1 =februaryAND leapyear = 1)然后
Days29
ElseIf (A1 =februaryAND leapyear = 0)然后
Days28
Else
Days31
如果


解决方案


  1. 在Z1中,使用此公式,
     
      = DAY(DATEVALUE(A $ 1&& ROW(1:1)&,& B $ 1))
     

  2. 在Z2中,使用此公式,
     
      = IFERROR(IF(MONTH(DATEVALUE(A $ 1&& ROW 1:1)&& B $ 1))= MONTH(DATEVALUE(A $ 1&& ROW(2:2)&,& B $ 1)),DAY(DATEVALUE A $ 1&& ROW(2:2)&,& B $ 1)),),)
      ...并填写到Z31。

  3. 转到公式►定义的名称►名称管理器。当名称管理器对话框打开时,单击新建

  4. 给它一个名称(例如lstDOM),将其保留为Workbook范围,并提供以下内容: : 
      = Sheet1!$ Z $ 1:INDEX(Sheet1!$ Z:$ Z,MATCH(1e99,Sheet1!$ Z:$ Z))  ;
       
     

  5. 点击确定创建动态命名范围然后关闭

  6. 选择C1,转到数据►数据工具►数据验证。选择允许:列出并为源提供 = lstDOM

您的结果应该类似于以下内容。



< img src =https://i.stack.imgur.com/aDvQM.pngalt =动态范围的月份>


It has to be done without VBA.

I have a list of months to be filled in one cell, say A1. The options can be filled using Data Validation-List (=Months) which causes a dropdown to appear in A1. In cell B1 I enter a year number (for example 2000). Now I want C1 to contain a dropdown, the entries in which change on the basis of the data in A1 and B1. In my example, A1 offers the choices january, february, march, april, may, june, july, august, september, october, november and december.

If I select january or march or may or july or august or october or december (months with 31 days), I should get numbers between 1 and 31 as an option in C1.

If I select april or june or september or november (months with 30 days), I should get numbers between 1 and 30 as an option in C1.

If I select february, I must first check if an year is leap year with this formula:

=((MOD(B1;4)=0)*((MOD(B1;100)<>0)+(MOD(B1;400)=0))=1)

and based on result of this formula(TRUE or FALSE), I should get numbers between 1 and 28 (or 29 if is leap year) as an option in C1.

I have created lists, named Days30, Days31, Days28 and Days29. How can I use Data Validation to switch between those lists for my dropdown in C1?? I'm trying to translate this logic into Data Validation formula, but no luck:

If (A1 = "april" OR A1 = "june" OR A1 = "september" OR A1 = "november") Then 
    Days30
ElseIf (A1 = "february" AND leapyear = 1) Then 
    Days29  
ElseIf (A1 = "february" AND leapyear = 0) Then 
    Days28
Else                
    Days31
End if

解决方案

  1. In Z1 put this formula,
     
     =DAY(DATEVALUE(A$1&" "&ROW(1:1)&", "&B$1))
     
  2. In Z2 put this formula,
     
     =IFERROR(IF(MONTH(DATEVALUE(A$1&" "&ROW(1:1)&", "&B$1))=MONTH(DATEVALUE(A$1&" "&ROW(2:2)&", "&B$1)), DAY(DATEVALUE(A$1&" "&ROW(2:2)&", "&B$1)), ""), "")
     
     ... and fill down to Z31.
  3. Go to Formulas ► Defined Names ► Name Manager. When the Name Manager dialog opens, click New.
  4. Give it a name (e.g. lstDOM), leave it as Workbook scope and supply the following for the Refers to: 
      =Sheet1!$Z$1:INDEX(Sheet1!$Z:$Z, MATCH(1e99, Sheet1!$Z:$Z)) 
     
      
     
  5. Click OK to create the dynamic named range then Close.
  6. With C1 selected, go to Data ► Data Tools ► Data validation. Choose Allow: List and supply =lstDOM for the Source:.

Your results should resemble the following.

      

这篇关于动态更改一个月内的下载天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆