在Excel中使用VBA查找活动单元格的列标题名称 [英] Finding Active cell's column header name using VBA in excel
本文介绍了在Excel中使用VBA查找活动单元格的列标题名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个根据数据列表创建的表.如何查找每一列的标题文本
I have a table created from List of data. How to find the header text of each column
当我选择活动单元的标头时,其突出显示为橙色,但我想使用Visual Basic检索该值. 我可以找到excel工作表的地址,但是我需要表的列标题
When I select the activecell's header is high lighted to orange but I want to retrieve that value using visual basic. I am able to find excel sheet's address but I need table's column header
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
MsgBox Target.Value
MsgBox ActiveCell.Address
End Sub
推荐答案
如果所传递的单元格在表中,则将返回列标题.
This will return the column header, if the passed cell is in a table
Function TableHeader(cl As Range) As Variant
Dim lst As ListObject
Dim strHeading As String
Set lst = cl.ListObject
If Not lst Is Nothing Then
TableHeader = lst.HeaderRowRange.Cells(1, cl.Column - lst.Range.Column + 1).Value
Else
TableHeader = ""
End If
End Function
这篇关于在Excel中使用VBA查找活动单元格的列标题名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文