自动扩展公式范围

时间:2018-08-09 20:27:50

标签: excel excel-formula excel-tables

我有以下公式:

=IF(MAX(C2:F2)>0,COUNTIF(C2:F2,">1")/COUNT(C2:F2),0)

此公式位于结构化表的第二列中,并在表的右列中遍历。该公式从根本上告诉您有多少实例满足特定条件,并将其占实例总数的一小部分。因此,如果满足标准2次,并且有3个实例,我将获得2/3作为输出。

我已经研究了一个小时,我无法弄清楚。添加新列时,是否有办法让公式中的单元格区域自动展开?

2 个答案:

答案 0 :(得分:2)

您应该利用Here //////////////////////////////////// called refreshVolumes(true) //////////////////////////////////// 08-09 17:41:29.687 924-1811/? I/ActivityManager: START u0 {cmp=com.xxxxxxxxx.android.dev/com.xxxxxxxxx.app.ui.main.settings.storage.StorageActivity} from uid 10293 08-09 17:41:29.767 26451-26451/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: start thread's name -> Thread-9 08-09 17:41:29.768 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: thread.isInterrupted? above while false 08-09 17:41:29.927 924-995/? I/ActivityManager: Displayed com.xxxxxxxxx.android.dev/com.xxxxxxxxx.app.ui.main.settings.storage.StorageActivity: +210ms 08-09 17:41:33.269 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: in TRY ---> Thread-9 refreshVolumes: in runnable WHILE ---> Thread-9 08-09 17:41:33.271 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: thread.isInterrupted? above while false 08-09 17:41:36.772 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: in TRY ---> Thread-9 refreshVolumes: in runnable WHILE ---> Thread-9 08-09 17:41:36.773 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: thread.isInterrupted? above while false 08-09 17:41:40.274 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: in TRY ---> Thread-9 refreshVolumes: in runnable WHILE ---> Thread-9 08-09 17:41:40.275 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: thread.isInterrupted? above while false 08-09 17:41:43.776 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: in TRY ---> Thread-9 refreshVolumes: in runnable WHILE ---> Thread-9 08-09 17:41:43.777 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: thread.isInterrupted? above while false 08-09 17:41:47.278 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: in TRY ---> Thread-9 08-09 17:41:47.279 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: in runnable WHILE ---> Thread-9 08-09 17:41:47.280 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: thread.isInterrupted? above while false 08-09 17:41:50.780 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: in TRY ---> Thread-9 refreshVolumes: in runnable WHILE ---> Thread-9 refreshVolumes: thread.isInterrupted? above while false //////////////////////////////////// called refreshVolumes(false) //////////////////////////////////// 08-09 17:41:50.861 26451-26451/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: interrupt thread's name -> Thread-9 08-09 17:41:50.862 26451-26451/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: thread.isInterrupted? true refreshVolumes: thread.isInterrupted? 2x false 08-09 17:41:50.862 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: in runnable WHILE ---> Thread-9 refreshVolumes: thread.isInterrupted? above while false 08-09 17:41:54.362 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: in TRY ---> Thread-9 08-09 17:41:54.363 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: in runnable WHILE ---> Thread-9 08-09 17:41:54.376 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: thread.isInterrupted? above while false 08-09 17:41:57.878 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: in TRY ---> Thread-9 refreshVolumes: in runnable WHILE ---> Thread-9 08-09 17:41:57.879 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: thread.isInterrupted? above while false 08-09 17:42:01.380 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: in TRY ---> Thread-9 refreshVolumes: in runnable WHILE ---> Thread-9 08-09 17:42:01.381 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: thread.isInterrupted? above while false 08-09 17:42:04.882 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: in TRY ---> Thread-9 refreshVolumes: in runnable WHILE ---> Thread-9 08-09 17:42:04.883 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: thread.isInterrupted? above while false 08-09 17:42:08.384 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: in TRY ---> Thread-9 08-09 17:42:08.385 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: in runnable WHILE ---> Thread-9 refreshVolumes: thread.isInterrupted? above while false 08-09 17:42:11.886 26451-26676/com.xxxxxxxxx.android.dev D/StoragePresenter: refreshVolumes: in TRY ---> Thread-9 来获取所需表的一部分

Index

这将计算公式列右侧=IFERROR( COUNTIF( INDEX(YourTableName[@],1,(COLUMN([@FormulaColumn])-COLUMN(YourTableName[@])+2)): INDEX(YourTableName[@],1,COLUMNS(YourTableName[@])), ">1") / COUNT( INDEX(YourTableName[@],1,(COLUMN([@FormulaColumn])-COLUMN(YourTableName[@])+2)): INDEX(YourTableName[@],1,COLUMNS(YourTableName[@]))) ,0) 的单元格数,并将其除以公式列右侧非空白的单元格数。

此处的关键点是>1。添加列时,该数目会自动增加

注意:如果要在除数中包含空格,可以调整公式以适合

只需更改COLUMNS(YourTableName[@])YourTableName以适合您的数据

答案 1 :(得分:2)

根据我所能得到的数据,可以通过创建一个引用以下内容的命名范围来解决该问题:

=OFFSET($C$2,0,0,1, COLUMNS(myTable))

公式的更改为:

=IF(MAX(myRange)>0,COUNTIF(myRange,">1")/COUNT(myRANGE),0)
  • myTABLE是表的名称,
  • myRANGE是新命名范围的名称

工作方式:

命名范围对表中的列数进行计数,并在添加列时将其更新。偏移量锚定到表格的左侧,并向右延伸表格中的列数。该公式将单元格引用降低到指定范围内,以提高可读性。可以将其复制,拖动,粘贴并在整个位置移动,但仍指向正确的范围。有了足够的范围,您可以毫无问题地将其放在工作簿中的任何地方。

注意: 将工作表复制到新工作簿时,我最大的烦恼就是这种方法。命名范围太棒了,即使将工作簿范围的范围复制到新工作簿后,它也将指向原始工作簿。有时候,这是一件好事,但对于我们来说,这主要是一件令人讨厌的事。


我相信替代答案会补充第一个答案,因为在无数情况下,人们可能需要动态范围而同时又不需要表格。

这就是线索,有关更多信息,您可以搜索动态范围。或更具体地说:动态命名范围。


要回答您的问题:

是的,有可能,而且也非常方便。例如,打印区域可以扩展和收缩您的数据,并且很容易进行交互,因为您使用的是名称而不是地址。而且,当使用VBA时,我发现在其中使用命名范围通常比使用表更容易,也就是说,除非将表绑定到变量,否则在我看来它们是相等的。从根本上说,讨厌listobject("table name").listcolum("table colum name").datapropertyrange打字,我不得不打字时几乎会有内脏的反应。

创建动态命名范围的要点很简单。打开名称编辑器,命名一个范围,然后使用offset()counta()定义您的范围。对非空单元格进行计数会产生双重作用。它是重新计算范围的触发器,它提供了可以与偏移量一起使用以更改范围区域的索引。

这里是一个示例:=OFFSET($A$1,0,0,COUNTA($A:$A),1)


这很简单。除了一个例外,打印范围。

由于任何原因,打印范围的行为方式都不相同,并且不会像普通命名范围那样进行更新。要使其动态,您可以像通常那样创建一个命名范围。这将是您的打印范围,因此请对其进行计数。然后使您的打印范围引用该命名范围。这里的所有都是它的。第一个命名范围指向要打印的区域,而在该范围内的打印则指向该命名范围。