[Solved] Macro to find header in excel


This is for your example i have grouped the 2 file data in single sheet. please see the below snap.

I have created a small UDF to get your required output. Paste the below UDF in Module and you can directly call this from the cell itself.

Public Function searchstring(a As Range, b As Range)
    Dim Header As String
    For i = 1 To a.Columns.Count
        If Not a.Columns(i).Find(b) Is Nothing Then
            Header = a.Cells(1, i)
        End If
    Next i
    searchstring = Header
End Function

OUTPUT

enter image description here

EDIT:

use Exit For before Endif to get the first match header.

3

solved Macro to find header in excel