2016-10-12 231 views
-1

我在Excel中使用OFFSET時有問題。例如,我有一個表格,其值隨年份的不同而有所不同。 然後,我有一張表,其中一些值按年/月變化。在Excel的多行上使用SUMPRODUCT和OFFSET

!!Click here for the tables!!

我想例如寫式 = SUMPRODUCT((E2:E37)* OFFSET(A1,C2:C37,1),E2:E37) ,但它返回#VALUE!

總之,我想在C2中使用一個值的數組:C37即{1,1,1,1,1,1,1,1,1,1,1,1,2,2, 2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3}以獲得陣列{0.03 ,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.05,0.05 ,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,},然後將此數組用於SUMPRODUCT函數。

有人可以幫我解決#VALUE!問題?

提前致謝!

+0

在你的問題的公式似乎是利用從圖像表不同列? –

+0

不要太早 - 這實際上是一個非常有趣的問題。見http://www.pcreview.co.uk/threads/array-formula-use-of-offset-function-with-array-argument.1753122/ –

回答

0

顯然(我不知道這一點)偏移是不常見的,因爲它與數組一起使用時會返回一組範圍對象作爲第二個參數。如果您將它傳遞給它們,大多數函數都無法處理。但是如果你通過N函數,你會得到正確的答案。

=SUMPRODUCT((E2:E37)*N(OFFSET(A1,C2:C37,1))) 

=SUMPRODUCT((E2:E37),N(OFFSET(A1,C2:C37,1))) 

enter image description here

注意,這些似乎給#VALUE數組!當您通過評估公式運行它們時出現錯誤,但是在通過N函數後執行這些解決方案。

當然,這將是更簡單的方法,並使用帶幫助列的索引或Vlookup。我試圖做一個單一數組公式中不使用偏移時,首先想到的是這樣的: -

=SUM(E2:E37*MMULT(N(C2:C37=TRANSPOSE((ROW(A2:A4)-1))),B2:B4)) 

我倒覺得補償方式是更容易,更高效。

但是卻只在有類別的少數,你可以使用這個數組公式,可能是最簡單的方法這種特殊情況: -

=SUM(CHOOSE(C2:C37+1,0,B2,B3,B4)*E2:E37) 

上述公式僅適用於特殊情況下工作,而且'key'與查找列中的行號相同。偏移方法可以很容易地適用於併入查找: -

=SUM((E2:E37)*N(OFFSET(A1,IFERROR(MATCH(C2:C37,A2:A4,0),0),1))) 

See this reference