Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 数据之间的公式动态范围_Excel_Excel Formula - Fatal编程技术网

Excel 数据之间的公式动态范围

Excel 数据之间的公式动态范围,excel,excel-formula,Excel,Excel Formula,我需要一个可以使范围在其他数据之间扩展的公式。 在每个月的B列中,您可以将Foo或Bar作为值。 我需要统计每个月的食物和酒吧数量。但是也可以将范围从B6:B11扩展到例如B6:15,并且计数函数应该可以工作 但这不是动态的。 我知道你可以用OFFSET和COUNTA创建动态范围,但这不起作用,因为数据的结构不是这个公式所需要的 OFFSET($A$1,0,0,COUNTA($A:$A),1) 我制作了一个VBA UDF,它模拟CTRL+DOWN来查找下一个填充的单元格,但是由于Foos或b

我需要一个可以使范围在其他数据之间扩展的公式。
在每个月的B列中,您可以将
Foo
Bar
作为值。
我需要统计每个月的食物和酒吧数量。但是也可以将范围从B6:B11扩展到例如B6:15,并且计数函数应该可以工作

但这不是动态的。
我知道你可以用OFFSET和COUNTA创建动态范围,但这不起作用,因为数据的结构不是这个公式所需要的

OFFSET($A$1,0,0,COUNTA($A:$A),1)
我制作了一个VBA UDF,它模拟CTRL+DOWN来查找下一个填充的单元格,但是由于
Foos
bar
的计数稍后链接到另一个主工作簿,UDF将不起作用,UDF无法使用链接的值运行。(据我所知)

其中nextC和last为:

Function last(rng)
    last = Sheets("Sheet1").Cells(rng.Row, "A").End(xlDown).Row - 1 ' finds the last cell row in the current month
    ' with A5 as input it returns 11
End Function

Function nextC(rng)
    nextC = rng.Offset(1, 0).Row ' returns 6 if input is A5 
    ' there may be a better way to do this, I just couldn't think of it at the moment and just wanted to see if it worked
End Function
是否有任何公式可以复制UDF的含义,如图所示,如果动态范围介于两个数据之间,则为count。

如果需要帮助器列,那么这不是问题。

这应该可以做到:

D2
中的公式:

=COUNTIF(INDEX($B:$B,MATCH($C$1,$A$1:$A$1000,0)+1):INDEX($B:$B,MATCH(FALSE,INDEX($A:$A,MATCH($C$1,$A$1:$A$1000,0)+2):$A$1000="",0)+MATCH($C$1,$A$1:$A$1000,0)),D1)
通过CtrlShift输入

然后拖动到E2

添加新行时的结果:

A1000
范围更改为您案例中需要的任何范围。它只是为了确保你超过最后一行,我在这里放了一个字符串“End”来标记最后一行

Function last(rng)
    last = Sheets("Sheet1").Cells(rng.Row, "A").End(xlDown).Row - 1 ' finds the last cell row in the current month
    ' with A5 as input it returns 11
End Function

Function nextC(rng)
    nextC = rng.Offset(1, 0).Row ' returns 6 if input is A5 
    ' there may be a better way to do this, I just couldn't think of it at the moment and just wanted to see if it worked
End Function
=COUNTIF(INDEX($B:$B,MATCH($C$1,$A$1:$A$1000,0)+1):INDEX($B:$B,MATCH(FALSE,INDEX($A:$A,MATCH($C$1,$A$1:$A$1000,0)+2):$A$1000="",0)+MATCH($C$1,$A$1:$A$1000,0)),D1)