在excel中获取数据和总数

我有一个名为Sheet1的Excel工作表。 在这张表中我有12列如下:

| A | B | C | D | E | F | G | H | I | J | K | L --+------+-----+-----+-----+-----+-----+-----+-----+-----+------+------+------ 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 --+------+-----+-----+-----+-----+-----+-----+-----+-----+------+------+------ 2 | 200 | 200 | 300 | 300 | 400 | 400 | 500 | 500 | 500 | 500 | 500 | 500 

现在在单元格N5

 If I Enter 4 then I should get 300. If I Enter 12 then I should get 500. If I Enter 1 then I should get 200. 

而在N6单元格中,我应该把总数加到那个单元格。 让我用一个例子来解释一下:

 If I enter 4 then I should get 1000, because 200+200+300+300 = 1000 If I enter 12 then I should get 4800 because 200+200+300+300+400+400+500+500+500+500+500+500 = 4800. If I enter 1 then I should get 200, If I enter 7 then I should get 2300, because 200+200+300+300+400+400+500 = 2300. 

您可以使用INDEX(MATCH())对获取单个值,并将SUM与该范围内的第一个单元格合并,以获得总计。

SUM(INDEX(MATCH()))

N5中的公式是,

=INDEX($A$2:$L$2,MATCH($M$5,$A$1:$L$1,0))

N6中的公式是,

=SUM(A2:INDEX($A$2:$L$2,MATCH($M$5,$A$1:$L$1,0)))

如果在找不到input值时需要进行错误控制,请将它们与IFERROR函数结合使用。