2017-07-11 93 views
0

如何使用可讀的公式(即公式中的行/單元格按名稱而不是索引引用)來獲取指定表格中特定單元格的值?指定表中的單元格的值

enter image description here

在上述圖象我想顯示錶Financials的細胞(Income, Feb)的值。我可以使用什麼語法?

+0

^h (約翰遜),匹配(「收入」,表1 [財務],0),匹配(「2月」,表1 [#頭部],0)的索引匹配公式適合沿着'= INDEX )'https://exceljet.net/formula/two-way-lookup-with-index-and-match – maxhob17

+0

@ maxhob17如果這是最可讀的公式使用名稱我認爲我們必須放鬆那個願望 –

+0

我不知道更好的方法;我想你可以通過用VBA創建用戶定義函數來隱藏該公式的複雜性http://www.excel-easy.com/vba/examples/user-defined-function.html – maxhob17

回答

1

正如我提到的,你可以隱藏與用戶定義函數的複雜性,如

Public Function Financials(month As String, item As String) As String 

'Object to represent the table  
Dim lo As ListObject: Set lo = Range("Table1").ListObject 

'Integers to act as coordinates  
Dim x As Integer, y As Integer 

'Find the column 
x = lo.HeaderRowRange.Find(month).Column - lo.HeaderRowRange.Column + 1 

'Find the row 
y = lo.DataBodyRange.Columns(1).Find(item).Row - lo.HeaderRowRange.Row 

' Return the value at the coordinates x,y 
Financials = lo.DataBodyRange(y, x).Value 

End Function 

(更新Range("Table1").ListObject與表的名稱在您的工作簿,或者你可以另一個參數添加到函數)

你會然後調用工作簿中的細胞這一功能,如本例中

=Financials("Feb", "Profit")