I wrote the following custom function in Excel using the VBA editor, but it does not seem to work. When I invoke the function I get a #NAME? error in Excel. I do not understand what name Excel is not understanding. I just need the function to work.
Function SubStrMatch(Str, SubStr, SubStrRange)
For N = 1 To SubStrRange
If IsError(Mid(Str, Search(SubStr, Str, 1), Len(SubStr))) = True Then
SubStr = SubStr + 1
Else
N = SubStrRange
End If
SubStrMatch = SubStr
End Function
The function looks in a cell containing a String to see if it contains any of a list of Substrings. If no Substrings are found in the String, the function should output "". If a Substring is found in the String from the list of Substrings, the function should output the value of the Substring found.
Attached is the Excel spreadsheet I have been working with. I highlighted the cells containing the formula that are not working in red.
Function SubStrMatch(Str, SubStr, SubStrRange)
For N = 1 To SubStrRange
If IsError(Mid(Str, Search(SubStr, Str, 1), Len(SubStr))) = True Then
SubStr = SubStr + 1
Else
N = SubStrRange
End If
SubStrMatch = SubStr
End Function
The function looks in a cell containing a String to see if it contains any of a list of Substrings. If no Substrings are found in the String, the function should output "". If a Substring is found in the String from the list of Substrings, the function should output the value of the Substring found.
Attached is the Excel spreadsheet I have been working with. I highlighted the cells containing the formula that are not working in red.