可能有内置的方法来做到这一点,但你也可以编写自己的功能。
将这个代码在VBA Module
:
Public Function WHICHCOLS(searchValue As Double, srcRange As Range) As String
Dim rangeColumn As Range
Dim columnCell As Range
Dim headerRow As Long
headerRow = 1 ' HeaderInformation is in RowNr 1 '
WHICHCOLS = vbNullString
For Each rangeColumn In srcRange.Columns
For Each columnCell In rangeColumn.Cells
If columnCell = searchValue Then
If WHICHCOLS <> vbNullString Then WHICHCOLS = WHICHCOLS & ", "
WHICHCOLS = WHICHCOLS & srcRange.Parent.Cells(headerRow, columnCell.Column)
Exit For
End If
Next columnCell
Next rangeColumn
End Function
在Excel中的一个例子电话是:
=WHICHCOLS(7,A2:F3)