单元格在命名表中的值
我怎样才能得到一个特定的单元格在一个命名表中的值使用可读的公式(即一个公式,其中行/单元格是由名称而不是索引引用)?
在上面的图片中,我想显示表格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")