Hello Excel Forum.
I'm still doing stuff with product lists.
Latest thing is I've written a function that when passed two cell refs and a number of characters searches through the second cell for snippets of the length specified and then returns an integer for how many matches it was able to make.
The idea is you use it to match "Apple" against "Red Granny Smith Apples From Spain" or "Apples from Spain" or "Green Apples" etc.
It's a bit of an analogue tool but it can be handy.
My question is can I make this run more efficiently?
It's not terrible but I'm wondering if I could make it do this quicker.
Function PartSearch(firstcell As Range, secondcell As Range, number_of_chars As Integer) As Integer
Dim first_string As String
Dim second_string As String
Dim char_set As String
Dim the_count
Dim match_count
the_count = 0
match_count = 0
first_string = firstcell.Value
second_string = secondcell.Value
For the_count = 1 To (Len(first_string) - number_of_chars) + 1
char_set = Mid(first_string, the_count, number_of_chars)
If InStr(second_string, char_set) > 0 Then match_count = match_count + 1
Next
PartSearch = match_count
End Function
I also feel like there's probably a much more elegant way to do this.
Bookmarks