请参考表格中的excel单元格的头名和行号(vba)

问题描述:

我试图通过使用表头名称和使用VBA的行号来引用excel表中的单元格。

I'm trying to refer to a cell in an excel table by using the table header name and the row number using VBA.

这是可以吗?

在你的例子中, >

In your example, something like this:

Dim tb As ListObject
'assumes Table is the first one on the ActiveSheet
Set tb = ActiveSheet.ListObjects(1)
MsgBox tb.DataBodyRange.Cells(2, tb.ListColumns("header4").Index)