Help me improve my first Instr function

MarkoBox

New Member
Joined
May 16, 2016
Messages
2
So the problem im solving is as follows:
Im comparing a list of company names which are missing legal form and city(but sometimes they have a city or legal form or both), and a list of properly formated names, and then returning a properly formated name. Ive adapted wellsr substr code to make this:

Function proper(text As String) As String


Dim lastrow As Long
Dim i As Integer


lastrow = Sheets("sorted").Range("A30000").End(xlUp).Row
For i = 1 To lastrow
If InStr(1, LCase(text), LCase(Sheets("sorted").Range("A" & i)), vbTextCompare) <> 0 Then
proper = Sheets("sorted").Range("D" & i).Value
End If
Next i


End Function

Range A in "sorted" sheet containes only company name which it compares to unsorted string (because unsorted string is always longer) and returns value from D range which has proper names.
Its working well but its making some errors and I need help improving it

What I need help with is
1. What value does function return when it doesnt find anything, and can i make it return "nothing" for eg. if it doesnt find substring. Currently when it doesnt find anything it just returns blank cell with formula in it and im dumbfounded to how to adapt it to return something more descriptive.

2. Optimise the search. Try to search first those words which in sorted list start on the same letter as the word im trying to find, then if not found expand the search to entire list.
This is to try and eliminate errors where for eg im searching for "AirBus" and it returns Bus inc., Luxemburg.(note that im searching in reverse, comparing proper names to the one im trying to find).
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,214,833
Messages
6,121,858
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top