Mountaineer00
New Member
- Joined
- Feb 10, 2011
- Messages
- 12
I have a workbook that runs a macro to look up a value based on city entered. When a city is entered that is spelled wrong or does not exist, I receive a run time error and the auto filter is still used and I have to go to filter and deselect. What I would like to do is if the city is not found in list, have a personal message stating something like "City not Found" then the macro cease and reset back to the original box of "Please Enter City"<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
<o></o>
John Davis helped tremendously with the lookup function and I'm trying to expand on that. Below is the code that I'm currently using for lookup functions. I don't know how to keep from getting the error and not having the filter applied if wrong.<o></o>
<o></o>
Sub Store_Lookup()
Dim lr As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row + 1
Range("D5").Value = InputBox("Please Enter City Name:", "Lookup By City")<o></o>
Columns("B:B").AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=Range("D5").Value
Range("A61:A" & lr).SpecialCells(xlCellTypeVisible).Copy Range("E5")
Columns("B:B").AutoFilter
End Sub<o></o>
<o></o>
John Davis helped tremendously with the lookup function and I'm trying to expand on that. Below is the code that I'm currently using for lookup functions. I don't know how to keep from getting the error and not having the filter applied if wrong.<o></o>
<o></o>
Sub Store_Lookup()
Dim lr As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row + 1
Range("D5").Value = InputBox("Please Enter City Name:", "Lookup By City")<o></o>
Columns("B:B").AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=Range("D5").Value
Range("A61:A" & lr).SpecialCells(xlCellTypeVisible).Copy Range("E5")
Columns("B:B").AutoFilter
End Sub<o></o>