dynamic插入function

这是我使用Excel来解决这个问题的一个要求。

col A我有0秒和1秒之间的不同数量为0秒的1秒。 每次出现1我都希望在二进制列旁边的两列中给出两个数字之间的差别。 不过,我希望从前面的1所述的计算中获得结果。

我会应付不同的软件,但我怎样才能达到这一点与Excel?

=IF(A4=1,OFFSET(B4,MATCH(1,A5:A$1000,0),0)-OFFSET(C4,MATCH(1,A5:A$1000,0),),"")

D4和复制下来似乎工作。

编辑:

=(IF(A$=1, ,"")如下所示: IF(logical_test,value_if_true,value_if_false)其中,如果false为( 空白 ),则表示为“”。

value_if_trueColumnBColumnC值之间的差异,每个从OFFSET函数中定位,如in = OFFSET(引用,行,列,高度,宽度) 。

reference是公式插入到的行的适当列(即B4C4 ),所需的值是可变的“南”值。

MATCH ,如in = MATCH(lookup_value,lookup_array,[match_type])是根据具体情况确定偏移的范围。 按照相反的顺序,这里的参数是match_type = 0 (要求精确匹配), lookup_array和ColumnA一样多。 最初selectRow1000( A$1000 ),但可以根据需要进行扩展,但要根据相关Excel版本的行限制进行。

第一个参数lookup_value )当然是1因为这是包含要减去的值的行的标志。

如果在MATCH函数中没有A5之间的$ ,那么随着公式被复制下来,数组的大小会自动减小(顶部单元格行参考增加),从而find下一个实例(而不是一个又一个)。

使用VBA,我首先将公式设置为显示与“ones”相同的结果。 (假设我为此使用了D列。)

= if(A1 = 1; B1 – C1;“”)

然后,在VBA窗口中,执行以下操作:

 Dim i as integer Dim Filled as Collection Set Filled = new Colleciton 'this collection will stored filled lines 'store filled lines for i = 2 to 1000 'use your table limit if Sheet1.Cells(i, 4).Value <> "" then 'the 4 is for D column, i for the line Filled.Add i end if next 'now fill the E column with displaced values for i = 1 to Filled.Count - 1 Sheet1.Cells(Filled(i), 5).Value = Sheet1.Cells(Filled(i+1), 5).Value next 'please note there's a missing line (the last), it's up to you to decide how to fill it 'sorry I cannot debug this code 

我会把这个关联到一些表单事件或一个button。