繁体   English   中英

从左到右计算多列中的行,直到满足特定条件

[英]Count rows in multiple columns left to right until specific criteria is met

我有下表。 我将根据其他无关信息引用一个特定的数字。 让我们说具体的数字是30.我首先需要计算我的9月份列表中的30个数字然后移动到10月然后11月直到计数达到30.然后我需要计算所有缺失值,直到下一个值达到第30个计数上一个任务。 因此,对于这个例子,第30个数字将是11月19日。 失踪人数应该是11月15日55(如果我算了那个权利)。 然后将该值存储在单元格中。

我用以下公式获得了错过的天数: =IFERROR(SMALL(IF(ISERROR(MATCH(ROW(L$1:INDEX(L:L,N$2)),M$2:INDEX(M:M,COUNT(M:M)+ROW(M$1)),0)),ROW(L$1:INDEX(L:L,N$2))),ROW()-ROW(L$1)),"") (见表2专栏参考)

如果月份列中没有数据,则最大列值将为空白,因此错过的列也将没有数据。 我用以下公式设置: =IF(COUNTA(M:M)>1,31,"") (列表参见表2)

    Table 1    
   September max  missed  October  max   missed   November  max  missed
    1        30   4        1       31    2        2         30   1
    2             6        3             6        7              3
    3             7        4             7        9              4
    5             11       5             8        10             5
    8             12       12            9        11             6
    9             13       15            10       16             8
    10            14       20            11       17             12
    15            16       28            13       18             13
    22            17       30            14       19             14
    23            18       31            16       20             15
    24            19                     17       22             21
    25            20                     18       27             23
    29            21                     19       28             24
                  26                     21                      25
                  27                     22                      26
                  28                     23                      29
                  30                     24                      30
                                         25
                                         26
                                         27
                                         29

    Table 2
    L               M             N         O
    (blank)         September     max       missed

我知道如何写这个,但不知道语法:

    x = Select(Range("G8").Value)    
    'value that holds specific value (30 for above example)

    If x < 31 Then
    '30 days in September

            y = Count(M2:M32) Until = x
            'values in September

            z = Count(O2:O32) Until = value of y - 1
            'What if the last value is the 30th of September, how would you stop on August 31st?

            Range("A1").Value = z
            'value of z is stored in cell A1

                    Elseif x < 62 Then
                    '61 days in September and October

                    y2 = Count(M2:M32) & Count(Q2:Q32) Until = x
                    'Values in September and October

                    z2 = Count(R2:R32) & (S2:S32) Until =value of -1
                    'Again, if the last value is the 31st of October how would you stop on September 30th?

                    Range("A1").Value = z
                    'Value of z is stored in cell A1

                           Elseif
                           'continue for each month (12 times)

    End If

有些事情可能会导致我的建议出现问题(我刚想到的)。 我如何决定我的开始月份? 假设我想引用一个特定的单元格,那个单元格包含数字4.所以我想在四月开始,即使我在三月有数据。 另一种思考方式是March在2019年和4月在2018年。那么我怎么能把代码从12月回到1月? 假设Z列是12月,A列是1月。 我不一定希望我的代码只能从左到右阅读。 它需要从引用另一个单元格开始,然后如果年份发生变化则跳回到开始。

我为长度而道歉,但这是我最好的解释。 如果您有任何问题或我是否可以向任何人提供更多示例,图片等,请与我们联系。

我认为您应该将数据表重新组织为以下内容:

Day        Status
01.09.2018 ok
02.09.2018 ok
03.09.2018 ok
04.09.2018 missed
05.09.2018 ok
06.09.2018 missed
07.09.2018 missed
08.09.2018 ok
09.09.2018 ok
10.09.2018 ok
11.09.2018 missed
12.09.2018 missed
13.09.2018 missed
14.09.2018 missed
15.09.2018 ok
16.09.2018 missed
17.09.2018 missed
18.09.2018 missed
19.09.2018 missed
20.09.2018 missed
21.09.2018 missed
22.09.2018 ok
23.09.2018 ok
24.09.2018 ok
25.09.2018 ok
26.09.2018 missed
27.09.2018 missed
28.09.2018 missed
29.09.2018 ok
30.09.2018 missed
01.10.2018 ok
02.10.2018 ok
03.10.2018 ok
04.10.2018 ok
05.10.2018 ok
06.10.2018 ok
07.10.2018 ok
08.10.2018 ok
09.10.2018 ok
10.10.2018 ok
11.10.2018 ok
12.10.2018 ok
13.10.2018 ok
14.10.2018 ok
15.10.2018 ok
16.10.2018 ok
17.10.2018 ok
18.10.2018 ok
19.10.2018 ok
20.10.2018 ok
21.10.2018 ok
22.10.2018 ok
23.10.2018 ok
24.10.2018 ok
25.10.2018 ok
26.10.2018 ok
27.10.2018 ok
28.10.2018 ok
29.10.2018 ok
30.10.2018 ok
31.10.2018 missed

之后,您可以轻松管理您的计数,通过过滤找到您想要的任何内容,指定日期开始等

暂无
暂无

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

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