简体   繁体   English

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

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

I have the following table below. 我有下表。 I will be referencing a specific number based on other extraneous information. 我将根据其他无关信息引用一个特定的数字。 Lets say the specific number is 30. I first need to count 30 numbers down my September list then move to October then November until count has reached 30. Then I need to count all the missing values until the next value would reach the 30th count from the previous task. 让我们说具体的数字是30.我首先需要计算我的9月份列表中的30个数字然后移动到10月然后11月直到计数达到30.然后我需要计算所有缺失值,直到下一个值达到第30个计数上一个任务。 So for this example the 30th number would be November 19th. 因此,对于这个例子,第30个数字将是11月19日。 The count of the missing should be 55, November 15th (if I counted that right). 失踪人数应该是11月15日55(如果我算了那个权利)。 That value would then be stored in a cell. 然后将该值存储在单元格中。

I obtained the missed days with the following formula: =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)),"") (see table 2 for column reference) 我用以下公式获得了错过的天数: =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专栏参考)

The max column value will be blank if there is no data in the month column, therefore the missed column will also have not data. 如果月份列中没有数据,则最大列值将为空白,因此错过的列也将没有数据。 I set that up with the following formula: =IF(COUNTA(M:M)>1,31,"") (see table 2 for column reference) 我用以下公式设置: =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

I have an idea of how I would write this, but do not know the syntax: 我知道如何写这个,但不知道语法:

    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

There are a couple of things that could cause some problems here with my suggestions (that I just thought of). 有些事情可能会导致我的建议出现问题(我刚想到的)。 How would I dictate my starting month? 我如何决定我的开始月份? Lets say I wanted to reference a specific cell and that cell contains the number 4. So I would want to start in April, even if I had data in March. 假设我想引用一个特定的单元格,那个单元格包含数字4.所以我想在四月开始,即使我在三月有数据。 Another way of thinking about this is March is in year 2019 and April is in 2018. So then how could I could I get the code to jump from say December back to January? 另一种思考方式是March在2019年和4月在2018年。那么我怎么能把代码从12月回到1月? Say column Z is December and column A is January. 假设Z列是12月,A列是1月。 I wouldn't necessarily want my code to only read left to right. 我不一定希望我的代码只能从左到右阅读。 It would need to start in reference to another cell and then jump back to the start if the year changes. 它需要从引用另一个单元格开始,然后如果年份发生变化则跳回到开始。

I apologies for the lengthiness, but that's my best effort in explaining. 我为长度而道歉,但这是我最好的解释。 Let me know if you have any questions or if I can provide anyone with more example, pictures, etc. 如果您有任何问题或我是否可以向任何人提供更多示例,图片等,请与我们联系。

I think you should reorganize your data table to something like this: 我认为您应该将数据表重新组织为以下内容:

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

After that, you could easily manage your counts, find anything you want via filtering, specifying date start and so on 之后,您可以轻松管理您的计数,通过过滤找到您想要的任何内容,指定日期开始等

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

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