I wrote a function that search for required string and returns column number of that string. But it is not accurately returning the column numbers when duplicate of strings are in the range( ex: "abc" and "abc ghed" ; when I searched for word "abc" it is retuning the column number of "abc ghed"). Can you please help me to make it accurate.
Function ColumnNumber(SearStr As Variant)
Dim c As Variant Dim sh As Worksheet
Dim colcount As Long Set sh= Sheets("SheeName")
colcount = sheet.UsedRange.Columns.Count
For Each c In sheet.Range(sh.Cells(1, 1), sh.Cells(3, colcount))
If c.Value = SearStr Then
ColumnNumber = sh.Cells.Find(SearStr).Column
ColumnAddres = Mid(c.Address, 2, InStr(2, c.Address, "$") - 2)
End If
Next c
End Function '
Function ColumnNumber(SearStr As Variant)
Dim c As Variant Dim sh As Worksheet
Dim colcount As Long Set sh= Sheets("SheeName")
colcount = sheet.UsedRange.Columns.Count
For Each c In sheet.Range(sh.Cells(1, 1), sh.Cells(3, colcount))
If c.Value = SearStr Then
ColumnNumber = sh.Cells.Find(SearStr).Column
ColumnAddres = Mid(c.Address, 2, InStr(2, c.Address, "$") - 2)
End If
Next c
End Function '
Last edited: