0
如何使用可读的公式(即公式中的行/单元格按名称而不是索引引用)来获取指定表格中特定单元格的值?指定表中的单元格的值
在上述图象我想显示表Financials
的细胞(Income, Feb)
的值。我可以使用什么语法?
如何使用可读的公式(即公式中的行/单元格按名称而不是索引引用)来获取指定表格中特定单元格的值?指定表中的单元格的值
在上述图象我想显示表Financials
的细胞(Income, Feb)
的值。我可以使用什么语法?
正如我提到的,你可以隐藏与用户定义函数的复杂性,如
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")
^h (约翰逊),匹配(“收入”,表1 [财务],0),匹配(“2月”,表1 [#头部],0)的索引匹配公式适合沿着'= INDEX )'https://exceljet.net/formula/two-way-lookup-with-index-and-match – maxhob17
@ maxhob17如果这是最可读的公式使用名称我认为我们必须放松那个愿望 –
我不知道更好的方法;我想你可以通过用VBA创建用户定义函数来隐藏该公式的复杂性http://www.excel-easy.com/vba/examples/user-defined-function.html – maxhob17