Last active
May 20, 2020 03:36
-
-
Save Hunu/16b42e4f069a6a16766f98bd66e09562 to your computer and use it in GitHub Desktop.
This is a User Defined Formula in EXCEL, which will looking for the first cell that contains(NOT the 'match') the str_to_find in a column, and return it's number of row.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function find_str_in_a_column(str_to_find As String, col_no As Integer, wws As Worksheet) As Integer | |
'In {wws}(working worksheet), column of {col_no},RETURN the row number of the first cell which contains {str_to_find} | |
'Or return -1 if not found | |
Dim arr() | |
Dim re As Integer | |
Dim i As Integer | |
With wws | |
re = .Cells(65536, col_no).End(xlUp).Row | |
arr = .Range(.Cells(1, col_no), .Cells(re, col_no)).Value2 | |
End With | |
find_str_in_a_column = -1 | |
For i = 1 To re | |
If InStr(1, arr(i, 1), str_to_find) > 0 Then | |
find_str_in_a_column = i | |
exit function | |
End If | |
next i | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment