如何在Excel中获取表格上方的单元格值

时间:2017-06-09 11:22:29

标签: excel excel-vba cell vba

我有一个循环遍历所有表格的功能。每个循环都有一个循环,循环遍历工作表中的所有表。

我无法弄清楚如何获取直接位于表列标题上方的单元格的值。

See Image

For Each sh In ActiveWorkbook.Worksheets
    If ActiveSheet.Name <> sh.Name And Not sh.Name = "Template" Then
        For Each tbl In sh.ListObjects
            I need those values here
        Next tbl
    End If
Next sh

1 个答案:

答案 0 :(得分:0)

你回答了自己的问题(差不多):

Option Explicit

Public Sub tblTitle()

    Dim sh As Worksheet, tbl As ListObject

    For Each sh In ActiveWorkbook.Worksheets
        If ActiveSheet.Name <> sh.Name And Not sh.Name = "Template" Then
            For Each tbl In sh.ListObjects
                With tbl.Range(1, 1)
                    If .Row > 1 Then MsgBox .Offset(-1, 0)
                End With
            Next tbl
        End If
    Next sh
End Sub

对于下图中的表格,它将显示2条消息:“A”和“B” enter image description here