可能有內置的方法來做到這一點,但你也可以編寫自己的功能。
將這個代碼在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)